• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PARAM_UTILS_H
17 #define BASE_STARTUP_PARAM_UTILS_H
18 #include <stddef.h>
19 #include <stdint.h>
20 
21 #include "beget_ext.h"
22 #include "init_param.h"
23 #include "init_utils.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 typedef enum {
32     PARAM_CODE_NOT_INIT = PARAM_CODE_MAX + 1,
33     PARAM_CODE_ERROR_MAP_FILE,
34 } PARAM_INNER_CODE;
35 
36 #ifndef PARAM_BUFFER_MAX
37 #define PARAM_BUFFER_MAX (0x01 << 16)
38 #endif
39 
40 struct CmdLineEntry {
41     char *key;
42     int set;
43 };
44 
45 typedef struct cmdLineInfo {
46     const char *name;
47     int (*processor)(const char *name, const char *value, int);
48 } cmdLineInfo;
49 
50 #define FILENAME_LEN_MAX 255
51 #define MS_UNIT 1000
52 #ifndef UNUSED
53 #define UNUSED(x) (void)(x)
54 #endif
55 #define PARAM_ALIGN(len) (((len) + 0x03) & (~0x03))
56 #define PARAM_IS_ALIGNED(x) (((x) & 0x03) == 0)
57 #define PARAM_ENTRY(ptr, type, member) (type *)((char *)(ptr)-offsetof(type, member))
58 
59 #define IS_READY_ONLY(name) \
60     ((strncmp((name), "const.", strlen("const.")) == 0) || (strncmp((name), "ro.", strlen("ro.")) == 0))
61 #define PARAM_PERSIST_PREFIX "persist."
62 
63 #define SYS_POWER_CTRL "ohos.startup.powerctrl="
64 #define OHOS_CTRL_START "ohos.ctl.start="
65 #define OHOS_CTRL_STOP "ohos.ctl.stop="
66 #define OHOS_SERVICE_CTRL_PREFIX "ohos.servicectrl."
67 #define OHOS_BOOT "ohos.boot."
68 
69 #ifdef STARTUP_INIT_TEST
70 #define PARAM_STATIC
71 #else
72 #define PARAM_STATIC static
73 #endif
74 
75 #ifdef __LITEOS_M__
76 #ifndef DATA_PATH
77 #define DATA_PATH          "/"
78 #endif
79 #elif defined __LITEOS_A__
80 #define DATA_PATH          STARTUP_INIT_UT_PATH"/storage/data/system/param/"
81 #elif defined __LINUX__
82 #define DATA_PATH          STARTUP_INIT_UT_PATH"/storage/data/system/param/"
83 #else
84 #define DATA_PATH          STARTUP_INIT_UT_PATH"/data/service/el1/startup/parameters/"
85 #endif
86 #define PARAM_AREA_SIZE_CFG STARTUP_INIT_UT_PATH"/etc/param/ohos.para.size"
87 
88 #define CLIENT_PIPE_NAME "/dev/unix/socket/paramservice"
89 #define PIPE_NAME STARTUP_INIT_UT_PATH "/dev/unix/socket/paramservice"
90 #define PARAM_STORAGE_PATH STARTUP_INIT_UT_PATH "/dev/__parameters__"
91 #define PARAM_PERSIST_SAVE_PATH DATA_PATH "persist_parameters"
92 #define PARAM_PERSIST_SAVE_TMP_PATH DATA_PATH "tmp_persist_parameters"
93 
94 #define WORKSPACE_FLAGS_INIT 0x01
95 #define WORKSPACE_FLAGS_LOADED 0x02
96 #define WORKSPACE_FLAGS_UPDATE 0x04
97 #define WORKSPACE_FLAGS_LABEL_LOADED 0x08
98 
99 #define PARAM_SET_FLAG(node, flag) ((node) |= (flag))
100 #define PARAM_CLEAR_FLAG(node, flag) ((node) &= ~(flag))
101 #define PARAM_TEST_FLAG(node, flag) (((node) & (flag)) == (flag))
102 
103 #ifndef PARAN_DOMAIN
104 #define PARAN_DOMAIN (BASE_DOMAIN + 2)
105 #endif
106 #define PARAN_LABEL "PARAM"
107 #ifdef PARAM_BASE
108 INIT_LOCAL_API void ParamWorBaseLog(InitLogLevel logLevel, uint32_t domain, const char *tag, const char *fmt, ...);
109 #define PARAM_LOGV(fmt, ...) \
110     ParamWorBaseLog(INIT_DEBUG, PARAN_DOMAIN, PARAN_LABEL, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
111 #define PARAM_LOGI(fmt, ...) \
112     ParamWorBaseLog(INIT_INFO, PARAN_DOMAIN, PARAN_LABEL, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
113 #define PARAM_LOGW(fmt, ...) \
114     ParamWorBaseLog(INIT_WARN, PARAN_DOMAIN, PARAN_LABEL, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
115 #define PARAM_LOGE(fmt, ...) \
116     ParamWorBaseLog(INIT_ERROR, PARAN_DOMAIN, PARAN_LABEL, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
117 #else
118 #define PARAM_LOGI(fmt, ...) STARTUP_LOGI(PARAN_DOMAIN, PARAN_LABEL, fmt, ##__VA_ARGS__)
119 #define PARAM_LOGE(fmt, ...) STARTUP_LOGE(PARAN_DOMAIN, PARAN_LABEL, fmt, ##__VA_ARGS__)
120 #define PARAM_LOGV(fmt, ...) STARTUP_LOGV(PARAN_DOMAIN, PARAN_LABEL, fmt, ##__VA_ARGS__)
121 #define PARAM_LOGW(fmt, ...) STARTUP_LOGW(PARAN_DOMAIN, PARAN_LABEL, fmt, ##__VA_ARGS__)
122 #endif
123 
124 #define PARAM_CHECK(retCode, exper, ...) \
125     if (!(retCode)) {                \
126         PARAM_LOGE(__VA_ARGS__);     \
127         exper;                       \
128     }
129 
130 #define PARAM_ONLY_CHECK(retCode, exper) \
131     if (!(retCode)) {                \
132         exper;                       \
133     }
134 
135 typedef int (*DUMP_PRINTF)(const char *fmt, ...);
136 #define PARAM_DUMP g_printf
137 #define MAX_LABEL_LEN 256
138 #define PARAM_BUFFER_SIZE 256
139 
140 #define SUBSTR_INFO_NAME 0
141 #define SUBSTR_INFO_VALUE 1
142 #ifdef PARAM_SUPPORT_SELINUX
143 #define SUBSTR_INFO_LABEL 1
144 #define SUBSTR_INFO_DAC 2
145 #else
146 #define SUBSTR_INFO_LABEL 1
147 #define SUBSTR_INFO_DAC 1
148 #endif
149 
150 INIT_LOCAL_API int SplitParamString(char *line, const char *exclude[], uint32_t count,
151     int (*result)(const uint32_t *context, const char *name, const char *value), const uint32_t *context);
152 #ifdef __cplusplus
153 #if __cplusplus
154 }
155 #endif
156 #endif
157 #endif