fs_manager.h 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef STARTUP_FS_MANAGER_H
#define STARTUP_FS_MANAGER_H

S
sun_fan 已提交
19
#include <stdbool.h>
X
add ut  
xionglei6 已提交
20
#include <stdio.h>
S
sun_fan 已提交
21

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

/* Fs manager flags definition */
#define FS_MANAGER_CHECK  0x00000001
#define FS_MANAGER_WAIT  0x00000002
#define FS_MANAGER_REQUIRED  0x00000004

#define VALID_FS_MANAGER_FLAGS (FS_MANAGER_CHECK | FS_MANAGER_WAIT | FS_MANAGER_REQUIRED)
#define FS_MANAGER_FLAGS_ENABLED(fsMgrFlags, flag) (((fsMgrFlags) & FS_MANAGER_##flag) != 0)

#define FM_MANAGER_CHECK_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), CHECK)
#define FM_MANAGER_WAIT_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), WAIT)
#define FM_MANAGER_REQUIRED_ENABLED(fsMgrFlags) FS_MANAGER_FLAGS_ENABLED((fsMgrFlags), REQUIRED)

typedef enum MountStatus {
    MOUNT_ERROR = -1,
    MOUNT_UMOUNTED = 0,
    MOUNT_MOUNTED = 1,
} MountStatus;

typedef struct FstabItem {
    char *deviceName;  // Block device name
    char *mountPoint;  // Mount point
    char *fsType;      // File system type
S
sun_fan 已提交
50
    char *mountOptions;  // File system mount options. readonly, rw, remount etc.
51 52 53 54 55 56 57 58 59 60 61 62
    unsigned int fsManagerFlags;  // flags defined by fs manager.
    struct FstabItem *next;
} FstabItem;

typedef struct {
    struct FstabItem *head;
} Fstab;

void ReleaseFstab(Fstab *fstab);
Fstab *ReadFstabFromFile(const char *file, bool procMounts);
FstabItem *FindFstabItemForPath(Fstab fstab, const char *path);
FstabItem* FindFstabItemForMountPoint(Fstab fstab, const char *mp);
63
char *GetFstabFile(void);
X
xionglei6 已提交
64
int GetBlockDeviceByMountPoint(const char *mountPoint, const Fstab *fstab, char *deviceName, int nameLen);
65 66 67 68
bool IsSupportedFilesystem(const char *fsType);
int DoFormat(const char *devPath, const char *fsType);
int MountOneItem(FstabItem *item);
MountStatus GetMountStatusForMountPoint(const char *mp);
X
xionglei6 已提交
69 70
int MountAllWithFstabFile(const char *fstabFile, bool required);
int MountAllWithFstab(const Fstab *fstab, bool required);
71
int UmountAllWithFstabFile(const char *file);
S
sun_fan 已提交
72
unsigned long GetMountFlags(char *mountFlag, char *fsSpecificFlags, size_t fsSpecificFlagSize);
73 74 75 76 77 78
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

X
add ut  
xionglei6 已提交
79
#endif // STARTUP_FS_MANAGER_H