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 #ifndef STARTUP_INIT_TEST 29 #ifndef INIT_STATIC 30 #define INIT_STATIC static 31 #endif 32 #else 33 #ifndef INIT_STATIC 34 #define INIT_STATIC 35 #endif 36 #endif 37 38 /* Fs manager flags definition */ 39 #define FS_MANAGER_CHECK 0x00000001 40 #define FS_MANAGER_WAIT 0x00000002 41 #define FS_MANAGER_REQUIRED 0x00000004 42 #define FS_MANAGER_NOFAIL 0x00000008 43 #define FS_MANAGER_HVB 0x00000010 44 #define FS_MANAGER_PROJQUOTA 0x00000020 45 #define FS_MANAGER_CASEFOLD 0x00000040 46 #define FS_MANAGER_COMPRESSION 0x00000080 47 #define FS_MANAGER_DEDUP 0x00000100 48 #define FS_MANAGER_FORMATTABLE 0x00000200 49 #define NAME_SIZE 32 50 #define MAX_SLOT 2 51 #define HVB_DEV_NAME_SIZE 64 52 53 #define VALID_FS_MANAGER_FLAGS (FS_MANAGER_CHECK | FS_MANAGER_WAIT | FS_MANAGER_REQUIRED) 54 #define FS_MANAGER_FLAGS_ENABLED(fsMgrFlags, flag) (((fsMgrFlags) & FS_MANAGER_##flag) != 0) 55 56 #define FM_MANAGER_CHECK_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), CHECK) 57 #define FM_MANAGER_WAIT_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), WAIT) 58 #define FM_MANAGER_REQUIRED_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), REQUIRED) 59 #define FM_MANAGER_NOFAIL_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), NOFAIL) 60 #define FM_MANAGER_FORMATTABLE_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), FORMATTABLE) 61 62 typedef enum MountStatus { 63 MOUNT_ERROR = -1, 64 MOUNT_UMOUNTED = 0, 65 MOUNT_MOUNTED = 1, 66 } MountStatus; 67 68 typedef struct FstabItem { 69 char *deviceName; // Block device name 70 char *mountPoint; // Mount point 71 char *fsType; // File system type 72 char *mountOptions; // File system mount options. readonly, rw, remount etc. 73 unsigned int fsManagerFlags; // flags defined by fs manager. 74 struct FstabItem *next; 75 } FstabItem; 76 77 typedef struct { 78 struct FstabItem *head; 79 struct FstabItem *tail; 80 } Fstab; 81 82 typedef struct { 83 char partName[HVB_DEV_NAME_SIZE]; 84 int reverse; // 0 :system->dm0 1:dm0->system 85 char value[HVB_DEV_NAME_SIZE]; 86 int len; 87 } HvbDeviceParam; 88 89 typedef enum SlotFlag { 90 UNBOOT = 0, 91 ACTIVE = 1, 92 } SlotFlag; 93 94 typedef struct SlotInfo { 95 int slotName; 96 char *slotSuffix; 97 SlotFlag slotFlag; 98 unsigned int retryCount; 99 unsigned int reserved; 100 } SlotInfo; 101 102 Fstab* LoadFstabFromCommandLine(void); 103 int GetBootSlots(void); 104 int GetCurrentSlot(void); 105 void ReleaseFstab(Fstab *fstab); 106 Fstab *ReadFstabFromFile(const char *file, bool procMounts); 107 FstabItem *FindFstabItemForPath(Fstab fstab, const char *path); 108 FstabItem* FindFstabItemForMountPoint(Fstab fstab, const char *mp); 109 int ParseFstabPerLine(char *str, Fstab *fstab, bool procMounts, const char *separator); 110 111 int GetBlockDeviceByMountPoint(const char *mountPoint, const Fstab *fstab, char *deviceName, int nameLen); 112 int GetBlockDeviceByName(const char *deviceName, const Fstab *fstab, char* miscDev, size_t size); 113 bool IsSupportedFilesystem(const char *fsType); 114 int DoFormat(const char *devPath, const char *fsType); 115 int MountOneItem(FstabItem *item); 116 MountStatus GetMountStatusForMountPoint(const char *mp); 117 int MountAllWithFstabFile(const char *fstabFile, bool required); 118 int MountAllWithFstab(const Fstab *fstab, bool required); 119 int UmountAllWithFstabFile(const char *file); 120 int MountOneWithFstabFile(const char *fstabFile, const char *devName, bool required); 121 int FsManagerDmRemoveDevice(const char *devName); 122 unsigned long GetMountFlags(char *mountFlag, char *fsSpecificFlags, size_t fsSpecificFlagSize, 123 const char *mountPoint); 124 125 int GetBlockDevicePath(const char *partName, char *path, size_t size); 126 127 // Get fscrypt policy if exist 128 int LoadFscryptPolicy(char *buf, size_t size); 129 #ifdef __cplusplus 130 #if __cplusplus 131 } 132 #endif 133 #endif 134 135 #endif // STARTUP_FS_MANAGER_H 136