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 struct FstabItem *tail; 63 } Fstab; 64 65 typedef enum SlotFlag { 66 UNBOOT = 0, 67 ACTIVE = 1, 68 } SlotFlag; 69 70 typedef struct SlotInfo { 71 int slotName; 72 char *slotSuffix; 73 SlotFlag slotFlag; 74 unsigned int retryCount; 75 unsigned int reserved; 76 } SlotInfo; 77 78 Fstab* LoadFstabFromCommandLine(void); 79 int GetBootSlots(void); 80 int GetCurrentSlot(void); 81 void ReleaseFstab(Fstab *fstab); 82 Fstab *ReadFstabFromFile(const char *file, bool procMounts); 83 FstabItem *FindFstabItemForPath(Fstab fstab, const char *path); 84 FstabItem* FindFstabItemForMountPoint(Fstab fstab, const char *mp); 85 int ParseFstabPerLine(char *str, Fstab *fstab, bool procMounts, const char *separator); 86 87 int GetBlockDeviceByMountPoint(const char *mountPoint, const Fstab *fstab, char *deviceName, int nameLen); 88 int GetBlockDeviceByName(const char *deviceName, const Fstab *fstab, char* miscDev, size_t size); 89 bool IsSupportedFilesystem(const char *fsType); 90 int DoFormat(const char *devPath, const char *fsType); 91 int MountOneItem(FstabItem *item); 92 MountStatus GetMountStatusForMountPoint(const char *mp); 93 int MountAllWithFstabFile(const char *fstabFile, bool required); 94 int MountAllWithFstab(const Fstab *fstab, bool required); 95 int UmountAllWithFstabFile(const char *file); 96 unsigned long GetMountFlags(char *mountFlag, char *fsSpecificFlags, size_t fsSpecificFlagSize, 97 const char *mountPoint); 98 99 int GetBlockDevicePath(const char *partName, char *path, size_t size); 100 101 // Get fscrypt policy if exist 102 int LoadFscryptPolicy(char *buf, size_t size); 103 #ifdef __cplusplus 104 #if __cplusplus 105 } 106 #endif 107 #endif 108 109 #endif // STARTUP_FS_MANAGER_H 110