1 /* 2 * Copyright (c) 2021 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 BASE_STARTUP_INITLITE_UEVENTD_H 17 #define BASE_STARTUP_INITLITE_UEVENTD_H 18 #include <unistd.h> 19 #ifdef __cplusplus 20 #if __cplusplus 21 extern "C" { 22 #endif 23 #endif 24 25 // Refer to linux kernel kobject.h 26 typedef enum ACTION { 27 ACTION_ADD, 28 ACTION_REMOVE, 29 ACTION_CHANGE, 30 ACTION_MOVE, 31 ACTION_ONLINE, 32 ACTION_OFFLINE, 33 ACTION_BIND, 34 ACTION_UNBIND, 35 ACTION_UNKNOWN, 36 } ACTION; 37 38 struct UidGid { 39 uid_t uid; 40 gid_t gid; 41 }; 42 43 struct Uevent { 44 const char *subsystem; 45 const char *syspath; 46 // DEVNAME may has slash 47 const char *deviceName; 48 const char *partitionName; 49 const char *firmware; 50 ACTION action; 51 int partitionNum; 52 int major; 53 int minor; 54 struct UidGid ug; 55 // for usb device. 56 int busNum; 57 int devNum; 58 }; 59 60 typedef enum SUBYSTEM { 61 SUBSYSTEM_EMPTY = -1, 62 SUBSYSTEM_BLOCK = 0, 63 SUBSYSTEM_PLATFORM = 1, 64 SUBSYSTEM_FIRMWARE = 2, 65 SUBSYSTEM_OTHERS = 3, 66 } SUBSYSTEMTYPE; 67 68 #define CMDLINE_VALUE_LEN_MAX 512 69 #define UEVENTD_POLL_TIME 30000 70 #define UEVENTD_FLAG "/dev/.ueventd_trigger_done" 71 72 extern char bootDevice[CMDLINE_VALUE_LEN_MAX]; 73 74 const char *ActionString(ACTION action); 75 void ParseUeventMessage(const char *buffer, ssize_t length, struct Uevent *uevent); 76 void RetriggerUevent(int sockFd, char **devices, int num); 77 void RetriggerUeventByPath(int sockFd, char *path); 78 void ProcessUevent(int sockFd, char **devices, int num); 79 void CloseUeventConfig(void); 80 #ifdef __cplusplus 81 #if __cplusplus 82 } 83 #endif 84 #endif 85 #endif // BASE_STARTUP_INITLITE_UEVENTD_H 86