• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef STARTUP_FS_MANAGER_H
17 #define STARTUP_FS_MANAGER_H
18 
19 #include <stdbool.h>
20 #include <stdio.h>
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 /* Fs manager flags definition */
29 #define FS_MANAGER_CHECK  0x00000001
30 #define FS_MANAGER_WAIT  0x00000002
31 #define FS_MANAGER_REQUIRED  0x00000004
32 #define FS_MANAGER_NOFAIL  0x00000008
33 #define FS_MANAGER_HVB  0x00000010
34 #define NAME_SIZE 32
35 #define MAX_SLOT 2
36 
37 #define VALID_FS_MANAGER_FLAGS (FS_MANAGER_CHECK | FS_MANAGER_WAIT | FS_MANAGER_REQUIRED)
38 #define FS_MANAGER_FLAGS_ENABLED(fsMgrFlags, flag) (((fsMgrFlags) & FS_MANAGER_##flag) != 0)
39 
40 #define FM_MANAGER_CHECK_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), CHECK)
41 #define FM_MANAGER_WAIT_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), WAIT)
42 #define FM_MANAGER_REQUIRED_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), REQUIRED)
43 #define FM_MANAGER_NOFAIL_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), NOFAIL)
44 
45 typedef enum MountStatus {
46     MOUNT_ERROR = -1,
47     MOUNT_UMOUNTED = 0,
48     MOUNT_MOUNTED = 1,
49 } MountStatus;
50 
51 typedef struct FstabItem {
52     char *deviceName;  // Block device name
53     char *mountPoint;  // Mount point
54     char *fsType;      // File system type
55     char *mountOptions;  // File system mount options. readonly, rw, remount etc.
56     unsigned int fsManagerFlags;  // flags defined by fs manager.
57     struct FstabItem *next;
58 } FstabItem;
59 
60 typedef struct {
61     struct FstabItem *head;
62 } Fstab;
63 
64 typedef enum SlotFlag {
65     UNBOOT = 0,
66     ACTIVE = 1,
67 } SlotFlag;
68 
69 typedef struct SlotInfo {
70     int slotName;
71     char *slotSuffix;
72     SlotFlag slotFlag;
73     unsigned int retryCount;
74     unsigned int reserved;
75 } SlotInfo;
76 
77 Fstab* LoadFstabFromCommandLine(void);
78 int GetBootSlots(void);
79 int GetCurrentSlot(void);
80 void ReleaseFstab(Fstab *fstab);
81 Fstab *ReadFstabFromFile(const char *file, bool procMounts);
82 FstabItem *FindFstabItemForPath(Fstab fstab, const char *path);
83 FstabItem* FindFstabItemForMountPoint(Fstab fstab, const char *mp);
84 int ParseFstabPerLine(char *str, Fstab *fstab, bool procMounts, const char *separator);
85 
86 int GetBlockDeviceByMountPoint(const char *mountPoint, const Fstab *fstab, char *deviceName, int nameLen);
87 int GetBlockDeviceByName(const char *deviceName, const Fstab *fstab, char* miscDev, size_t size);
88 bool IsSupportedFilesystem(const char *fsType);
89 int DoFormat(const char *devPath, const char *fsType);
90 int MountOneItem(FstabItem *item);
91 MountStatus GetMountStatusForMountPoint(const char *mp);
92 int MountAllWithFstabFile(const char *fstabFile, bool required);
93 int MountAllWithFstab(const Fstab *fstab, bool required);
94 int UmountAllWithFstabFile(const char *file);
95 unsigned long GetMountFlags(char *mountFlag, char *fsSpecificFlags, size_t fsSpecificFlagSize,
96     const char *mountPoint);
97 
98 int GetBlockDevicePath(const char *partName, char *path, size_t size);
99 
100 // Get fscrypt policy if exist
101 int LoadFscryptPolicy(char *buf, size_t size);
102 #ifdef __cplusplus
103 #if __cplusplus
104 }
105 #endif
106 #endif
107 
108 #endif // STARTUP_FS_MANAGER_H
109