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