mirror of
https://gitee.com/openharmony/startup_init
synced 2025-01-23 20:04:35 +00:00
init: fix param ..
Signed-off-by: sun_fan <sun_fan1@hoperun.com>
This commit is contained in:
parent
017f716d4b
commit
b06d198c70
@ -1,39 +0,0 @@
|
||||
# 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.
|
||||
|
||||
build_version = 2.0
|
||||
|
||||
# whether ohos is enabled.
|
||||
hw_sc.build.os.enable=true
|
||||
|
||||
# ohos API version number.
|
||||
hw_sc.build.os.apiversion=6
|
||||
|
||||
# ohos system version.
|
||||
hw_sc.build.os.version=2.2.0
|
||||
|
||||
# ohos device type please use hw_sc.build.os.devicetype
|
||||
|
||||
# ohos release type
|
||||
hw_sc.build.os.releasetype=Canary1
|
||||
|
||||
ro.actionable_compatible_property.enabled=false
|
||||
ro.postinstall.fstab.prefix=/system
|
||||
ro.secure=1
|
||||
security.perf_harden=1
|
||||
ro.allow.mock.location=0
|
||||
ro.debuggable=1
|
||||
ro.build.characteristics="default"
|
||||
ro.product.model="ohos"
|
||||
ro.product.name="OpenHarmony 2.0 Canary"
|
||||
persist.sys.usb.config=hdc
|
@ -29,8 +29,7 @@ typedef struct ListNode {
|
||||
|
||||
#define ListEmpty(node) ((node).next == &(node) && (node).prev == &(node))
|
||||
#define ListEntry(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member)))
|
||||
#define ForEachListEntry(list, node) \
|
||||
(for (node = (list)->next; node != (list); node = node->next))
|
||||
#define ForEachListEntry(list, node) for (node = (list)->next; node != (list); node = node->next)
|
||||
|
||||
void ListInit(struct ListNode *list);
|
||||
void ListAddTail(struct ListNode *list, struct ListNode *item);
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "sys_param.h"
|
||||
|
||||
#define HELP_PARAM "--help"
|
||||
#define BUFFER_SIZE 256
|
||||
|
||||
static void ProcessParam(ParamHandle handle, void* cookie)
|
||||
{
|
||||
if (cookie == NULL) {
|
||||
printf("ProcessParam cookie is NULL\n");
|
||||
return;
|
||||
}
|
||||
SystemGetParameterName(handle, (char*)cookie, BUFFER_SIZE);
|
||||
u_int32_t size = BUFFER_SIZE;
|
||||
SystemGetParameterValue(handle, ((char*)cookie) + BUFFER_SIZE, &size);
|
||||
printf("\t%s = %s \n", (char*)cookie, ((char*)cookie) + BUFFER_SIZE);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc == 1) { // 显示所有的记录
|
||||
char value[BUFFER_SIZE + BUFFER_SIZE] = {0};
|
||||
SystemTraversalParameter(ProcessParam, (void*)value);
|
||||
return 0;
|
||||
}
|
||||
if (argc == 2 && strncmp(argv[1], HELP_PARAM, strlen(HELP_PARAM)) == 0) { // 显示帮助
|
||||
printf("usage: getparam NAME VALUE\n");
|
||||
return 0;
|
||||
}
|
||||
if (argc != 2) {
|
||||
printf("usage: getparam NAME VALUE\n");
|
||||
return 0;
|
||||
}
|
||||
char value[BUFFER_SIZE] = {0};
|
||||
u_int32_t size = BUFFER_SIZE;
|
||||
int ret = SystemGetParameter(argv[1], value, &size);
|
||||
if (ret == 0) {
|
||||
printf("%s \n", value);
|
||||
} else {
|
||||
printf("getparam %s %s fail\n", argv[1], value);
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sys_param.h"
|
||||
|
||||
#define HELP_PARAM "--help"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc == 1 || argc > 3) {
|
||||
printf("setparam: Need 2 arguments (see \"setparam --help\")\n");
|
||||
return 0;
|
||||
}
|
||||
if (argc == 2 && strncmp(argv[1], HELP_PARAM, strlen(HELP_PARAM)) == 0) {
|
||||
printf("usage: setparam NAME VALUE\n");
|
||||
return 0;
|
||||
}
|
||||
int ret = SystemSetParameter(argv[1], argv[2]);
|
||||
if (ret == 0) {
|
||||
printf("setparam %s %s success\n", argv[1], argv[2]);
|
||||
} else {
|
||||
printf("setparam %s %s fail\n", argv[1], argv[2]);
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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 BASE_STARTUP_EVENT_MANAGER_H
|
||||
#define BASE_STARTUP_EVENT_MANAGER_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sys_param.h"
|
||||
#include "init_param.h"
|
||||
#include "trigger_manager.h"
|
||||
#include "uv.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct TriggerEvent {
|
||||
uv_work_t request;
|
||||
EventType type;
|
||||
} TriggerEvent;
|
||||
|
||||
typedef struct {
|
||||
uv_work_t request;
|
||||
EventType type;
|
||||
u_int32_t contentSize;
|
||||
char content[0];
|
||||
} TriggerDataEvent;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
@ -1,148 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#include "sys_param.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "param_manager.h"
|
||||
|
||||
#define LABEL "Manager"
|
||||
#define MAX_PROPERT_IN_WATCH 5
|
||||
#define NORMAL_MEMORY_FOR_PARAM_CACHE 4 * 1024
|
||||
static WorkSpace g_workSpace;
|
||||
static pthread_mutex_t cacheLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static int InitNormalMemory(WorkSpace *workSpace, u_int32_t spaceSize)
|
||||
{
|
||||
PARAM_CHECK(workSpace != NULL, return -1, "Invalid param");
|
||||
if (workSpace->area != NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *areaAddr = (void *)mmap(NULL, spaceSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_POPULATE | MAP_ANON, -1, 0);
|
||||
PARAM_CHECK(areaAddr != MAP_FAILED, return -1, "Failed to map memory error %s", strerror(errno));
|
||||
workSpace->area = (WorkArea*)areaAddr;
|
||||
atomic_init(&workSpace->area->serial, 0);
|
||||
workSpace->area->dataSize = spaceSize;
|
||||
workSpace->area->currOffset = sizeof(WorkArea);
|
||||
PARAM_LOGI("InitNormalMemory success, currOffset %u firstNode %u dataSize %u",
|
||||
workSpace->area->currOffset, workSpace->area->firstNode, workSpace->area->dataSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ParamCacheNode *AllocParamCacheNode(WorkSpace *workSpace, u_int32_t size)
|
||||
{
|
||||
PARAM_CHECK(workSpace != NULL, return 0, "Invalid param");
|
||||
PARAM_CHECK((workSpace->area->currOffset + size) < workSpace->area->dataSize, return 0,
|
||||
"Failed to allocate currOffset %d, dataSize %d", workSpace->area->currOffset, workSpace->area->dataSize);
|
||||
ParamCacheNode *cache = (ParamCacheNode *)(workSpace->area->data + workSpace->area->currOffset);
|
||||
workSpace->area->currOffset += size;
|
||||
return cache;
|
||||
}
|
||||
|
||||
static int CreateParamCache(ParamCache *cache, ParamWorkSpace *workSpace, ParamEvaluatePtr evaluate)
|
||||
{
|
||||
PARAM_CHECK(cache != NULL && evaluate != NULL, return -1, "Invalid param");
|
||||
if (cache->cacheNode != NULL) {
|
||||
return 0;
|
||||
}
|
||||
int ret = InitNormalMemory(&g_workSpace, NORMAL_MEMORY_FOR_PARAM_CACHE);
|
||||
PARAM_CHECK(ret == 0, return -1, "Failed to init normal memory");
|
||||
pthread_mutex_init(&cache->lock, NULL);
|
||||
cache->serial = GetWorkSpaceSerial(&workSpace->paramSpace);
|
||||
cache->cacheCount = 0;
|
||||
cache->evaluate = evaluate;
|
||||
cache->cacheNode = (ParamCacheNode *)AllocParamCacheNode(&g_workSpace,
|
||||
sizeof(ParamCache) * MAX_PROPERT_IN_WATCH);
|
||||
PARAM_CHECK(cache->cacheNode != NULL, return -1, "Failed to malloc memory");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int AddParamNode(ParamCache *cache, ParamWorkSpace *workSpace, const char *name, const char *defValue)
|
||||
{
|
||||
PARAM_CHECK(cache != NULL && name != NULL, return -1, "Invalid param");
|
||||
PARAM_CHECK(cache->cacheCount < MAX_PROPERT_IN_WATCH, return -1, "Full param in cache");
|
||||
|
||||
ParamCacheNode *cacheNode = &cache->cacheNode[cache->cacheCount++];
|
||||
int ret = memcpy_s(cacheNode->value, sizeof(cacheNode->value), defValue, strlen(defValue));
|
||||
PARAM_CHECK(ret == 0, return -1, "Failed to copy default value");
|
||||
|
||||
ret = ReadParamWithCheck(workSpace, name, &cacheNode->handle);
|
||||
PARAM_CHECK(ret == 0, return -1, "Failed to read param");
|
||||
cacheNode->serial = ReadParamSerial(workSpace, cacheNode->handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int CheckCacheNode(ParamWorkSpace *workSpace, ParamCacheNode *cacheNode)
|
||||
{
|
||||
return cacheNode && ReadParamSerial(workSpace, cacheNode->handle) != cacheNode->serial;
|
||||
}
|
||||
|
||||
static void RefreshCacheNode(ParamWorkSpace *workSpace, ParamCacheNode *cacheNode)
|
||||
{
|
||||
cacheNode->serial = ReadParamSerial(workSpace, cacheNode->handle);
|
||||
u_int32_t len = sizeof(cacheNode->value);
|
||||
ReadParamValue(workSpace, cacheNode->handle, cacheNode->value, &len);
|
||||
}
|
||||
|
||||
static const char *TestParamCache(ParamCache *cache, ParamWorkSpace *workSpace)
|
||||
{
|
||||
int changeDetected = 0;
|
||||
if (pthread_mutex_trylock(&cache->lock)) {
|
||||
return cache->evaluate(cache->cacheCount, cache->cacheNode);
|
||||
}
|
||||
if (GetWorkSpaceSerial(&workSpace->paramSpace) != cache->serial) {
|
||||
changeDetected = 1;
|
||||
}
|
||||
for (u_int32_t i = 0; (i < cache->cacheCount) && changeDetected == 0; i++) {
|
||||
changeDetected = CheckCacheNode(workSpace, &cache->cacheNode[i]);
|
||||
}
|
||||
if (changeDetected) {
|
||||
for (u_int32_t i = 0; i < cache->cacheCount; i++) {
|
||||
RefreshCacheNode(workSpace, &cache->cacheNode[i]);
|
||||
}
|
||||
cache->serial = GetWorkSpaceSerial(&workSpace->paramSpace);
|
||||
}
|
||||
pthread_mutex_unlock(&cache->lock);
|
||||
|
||||
return cache->evaluate(cache->cacheCount, cache->cacheNode);
|
||||
}
|
||||
|
||||
const char *DetectParamChange(ParamWorkSpace *workSpace, ParamCache *cache,
|
||||
ParamEvaluatePtr evaluate, u_int32_t count, const char *parameters[][2])
|
||||
{
|
||||
pthread_mutex_lock(&cacheLock);
|
||||
while (cache->cacheCount == 0) {
|
||||
int ret = CreateParamCache(cache, workSpace, evaluate);
|
||||
PARAM_CHECK(ret == 0, break, "Failed to create cache");
|
||||
for (u_int32_t i = 0; i < count; i++) {
|
||||
ret = AddParamNode(cache, workSpace, parameters[i][0], parameters[i][1]);
|
||||
PARAM_CHECK(ret == 0, break, "Failed to add param cache");
|
||||
}
|
||||
PARAM_CHECK(ret == 0, break, "Failed to add param cache");
|
||||
}
|
||||
pthread_mutex_unlock(&cacheLock);
|
||||
return TestParamCache(cache, workSpace);
|
||||
}
|
@ -356,7 +356,7 @@ static void DoStart(const char *cmdContent, int maxArg)
|
||||
return;
|
||||
}
|
||||
|
||||
static void DoStop(const char* cmdContent, int maxArg)
|
||||
static void DoStop(const char *cmdContent, int maxArg)
|
||||
{
|
||||
struct CmdArgs *ctx = GetCmd(cmdContent, " ", maxArg);
|
||||
if (ctx == NULL || ctx->argv == NULL || ctx->argc != maxArg) {
|
||||
@ -371,7 +371,7 @@ static void DoStop(const char* cmdContent, int maxArg)
|
||||
return;
|
||||
}
|
||||
|
||||
static void DoReset(const char* cmdContent, int maxArg)
|
||||
static void DoReset(const char *cmdContent, int maxArg)
|
||||
{
|
||||
struct CmdArgs *ctx = GetCmd(cmdContent, " ", maxArg);
|
||||
if (ctx == NULL || ctx->argv == NULL || ctx->argc != maxArg) {
|
||||
@ -435,7 +435,7 @@ static void DoCopyInernal(const char *source, const char *target)
|
||||
dstFd = -1;
|
||||
}
|
||||
|
||||
static void DoCopy(const char* cmdContent, int maxArg)
|
||||
static void DoCopy(const char *cmdContent, int maxArg)
|
||||
{
|
||||
struct CmdArgs *ctx = GetCmd(cmdContent, " ", maxArg);
|
||||
if (ctx == NULL || ctx->argv == NULL || ctx->argc != DEFAULT_COPY_ARGS_CNT) {
|
||||
@ -462,7 +462,7 @@ static void DoCopy(const char* cmdContent, int maxArg)
|
||||
return;
|
||||
}
|
||||
|
||||
static void DoChown(const char* cmdContent, int maxArg)
|
||||
static void DoChown(const char *cmdContent, int maxArg)
|
||||
{
|
||||
struct CmdArgs *ctx = GetCmd(cmdContent, " ", maxArg);
|
||||
if (ctx == NULL || ctx->argv == NULL || ctx->argc != maxArg) {
|
||||
@ -484,7 +484,7 @@ static void DoChown(const char* cmdContent, int maxArg)
|
||||
return;
|
||||
}
|
||||
|
||||
static void DoMkDir(const char* cmdContent, int maxArg)
|
||||
static void DoMkDir(const char *cmdContent, int maxArg)
|
||||
{
|
||||
// mkdir support format:
|
||||
// 1.mkdir path
|
||||
@ -543,7 +543,7 @@ static void DoMkDir(const char* cmdContent, int maxArg)
|
||||
FreeCmd(ctx);
|
||||
}
|
||||
|
||||
static void DoChmod(const char* cmdContent, int maxArg)
|
||||
static void DoChmod(const char *cmdContent, int maxArg)
|
||||
{
|
||||
struct CmdArgs *ctx = GetCmd(cmdContent, " ", maxArg);
|
||||
if (ctx == NULL || ctx->argv == NULL || ctx->argc != maxArg) {
|
||||
@ -562,7 +562,7 @@ static void DoChmod(const char* cmdContent, int maxArg)
|
||||
return;
|
||||
}
|
||||
|
||||
static char* CopySubStr(const char* srcStr, size_t startPos, size_t endPos)
|
||||
static char* CopySubStr(const char *srcStr, size_t startPos, size_t endPos)
|
||||
{
|
||||
if (endPos <= startPos) {
|
||||
INIT_LOGE("DoMount, invalid params<%zu, %zu> for %s.", endPos, startPos, srcStr);
|
||||
@ -591,7 +591,7 @@ static char* CopySubStr(const char* srcStr, size_t startPos, size_t endPos)
|
||||
return retStr;
|
||||
}
|
||||
|
||||
static int GetMountFlag(unsigned long* mountflags, const char* targetStr, const char *source)
|
||||
static int GetMountFlag(unsigned long *mountflags, const char *targetStr, const char *source)
|
||||
{
|
||||
if (targetStr == NULL) {
|
||||
return 0;
|
||||
@ -615,7 +615,7 @@ static int GetMountFlag(unsigned long* mountflags, const char* targetStr, const
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int CountSpaces(const char* cmdContent, size_t* spaceCnt, size_t* spacePosArr, size_t spacePosArrLen)
|
||||
static int CountSpaces(const char *cmdContent, size_t *spaceCnt, size_t *spacePosArr, size_t spacePosArrLen)
|
||||
{
|
||||
*spaceCnt = 0;
|
||||
size_t strLen = strlen(cmdContent);
|
||||
@ -647,7 +647,7 @@ static int CountSpaces(const char* cmdContent, size_t* spaceCnt, size_t* spacePo
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void DoMount(const char* cmdContent, int maxArg)
|
||||
static void DoMount(const char *cmdContent, int maxArg)
|
||||
{
|
||||
size_t spaceCnt = 0;
|
||||
size_t spacePosArr[SPACES_CNT_IN_CMD_MAX] = {0};
|
||||
@ -808,7 +808,7 @@ static void DoInsmod(const char *cmdContent, int maxArg)
|
||||
return;
|
||||
}
|
||||
|
||||
static void DoSetParam(const char* cmdContent, int maxArg)
|
||||
static void DoSetParam(const char *cmdContent, int maxArg)
|
||||
{
|
||||
struct CmdArgs *ctx = GetCmd(cmdContent, " ", maxArg);
|
||||
if (ctx == NULL || ctx->argv == NULL || ctx->argc != maxArg) {
|
||||
@ -1181,7 +1181,7 @@ static void DoMakeDevice(const char *cmdContent, int maxArg)
|
||||
}
|
||||
#endif // __LITEOS__
|
||||
|
||||
void DoCmd(const CmdLine* curCmd)
|
||||
void DoCmd(const CmdLine *curCmd)
|
||||
{
|
||||
// null curCmd or empty command, just quit.
|
||||
if (curCmd == NULL || curCmd->name[0] == '\0') {
|
||||
@ -1248,7 +1248,7 @@ void DoCmdByName(const char *name, const char *cmdContent)
|
||||
}
|
||||
}
|
||||
|
||||
void ParseCmdLine(const char* cmdStr, CmdLine* resCmd)
|
||||
void ParseCmdLine(const char *cmdStr, CmdLine *resCmd)
|
||||
{
|
||||
size_t cmdLineLen = 0;
|
||||
if (cmdStr == NULL || resCmd == NULL || (cmdLineLen = strlen(cmdStr)) == 0) {
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
|
||||
#include "list.h"
|
||||
|
||||
void ListInit(struct ListNode *node)
|
||||
{
|
||||
node->next = node;
|
||||
node->prev = node;
|
||||
}
|
||||
|
||||
void ListAddTail(struct ListNode *head, struct ListNode *item)
|
||||
{
|
||||
item->next = head;
|
||||
item->prev = head->prev;
|
||||
head->prev->next = item;
|
||||
head->prev = item;
|
||||
}
|
||||
|
||||
void ListRemove(struct ListNode *item)
|
||||
{
|
||||
item->next->prev = item->prev;
|
||||
item->prev->next = item->next;
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 BASE_STARTUP_INITLITE_LIST_H
|
||||
#define BASE_STARTUP_INITLITE_LIST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct ListNode {
|
||||
struct ListNode *next;
|
||||
struct ListNode *prev;
|
||||
} ListNode;
|
||||
|
||||
#define ListEmpty(node) ((node).next == &(node) && (node).prev == &(node))
|
||||
#define ListEntry(ptr, type, member) (type *)((char *)(ptr) - offsetof(type, member))
|
||||
#define ForEachListEntry(list, node) \
|
||||
for (node = (list)->next; node != (list); node = node->next)
|
||||
|
||||
void ListInit(struct ListNode *list);
|
||||
void ListAddTail(struct ListNode *list, struct ListNode *item);
|
||||
void ListRemove(struct ListNode *item);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // BASE_STARTUP_INITLITE_LIST_H
|
@ -148,6 +148,41 @@ static int RemoveDeviceNode(const char *deviceNode, char **symLinks)
|
||||
return unlink(deviceNode);
|
||||
}
|
||||
|
||||
static char *FindPlatformDeviceName(char *path)
|
||||
{
|
||||
if (INVALIDSTRING(path)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (STARTSWITH(path, "/sys/devices/platform/")) {
|
||||
path += strlen("/sys/devices/platform/");
|
||||
return path;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void BuildDeviceSymbolLinks(char **links, int linkNum, const char *parent, const char *partitionName)
|
||||
{
|
||||
if (linkNum > BLOCKDEVICE_LINKS - 1) {
|
||||
INIT_LOGW("Too many links, ignore");
|
||||
return;
|
||||
}
|
||||
|
||||
// If a block device without partition name.
|
||||
// For now, we will not create symbol link for it.
|
||||
if (!INVALIDSTRING(partitionName)) {
|
||||
links[linkNum] = calloc(sizeof(char), DEVICE_FILE_SIZE);
|
||||
if (links[linkNum] == NULL) {
|
||||
INIT_LOGE("Failed to allocate memory for link, err = %d", errno);
|
||||
return;
|
||||
}
|
||||
if (snprintf_s(links[linkNum], DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1,
|
||||
"/dev/block/platform/%s/by-name/%s", parent, partitionName) == -1) {
|
||||
INIT_LOGE("Failed to build link");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
|
||||
{
|
||||
if (uevent == NULL || uevent->subsystem == NULL || STRINGEQUAL(uevent->subsystem, "block") == 0) {
|
||||
@ -172,6 +207,7 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
|
||||
int linkNum = 0;
|
||||
if (links == NULL) {
|
||||
INIT_LOGE("Failed to allocate memory for links, err = %d", errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Reverse walk through sysPath, and check subystem file under each directory.
|
||||
@ -184,39 +220,19 @@ static char **GetBlockDeviceSymbolLinks(const struct Uevent *uevent)
|
||||
}
|
||||
|
||||
char *bus = realpath(subsystem, NULL);
|
||||
if (bus == NULL) {
|
||||
goto loop;
|
||||
}
|
||||
|
||||
if (STRINGEQUAL(bus, "/sys/bus/platform")) {
|
||||
INIT_LOGD("Find a platform device: %s", parent);
|
||||
if (STARTSWITH(parent, "/sys/devices/platform/")) {
|
||||
parent += strlen("/sys/devices/platform/");
|
||||
if (linkNum > BLOCKDEVICE_LINKS - 1) {
|
||||
INIT_LOGW("Too much links, ignore");
|
||||
break;
|
||||
}
|
||||
links[linkNum] = calloc(sizeof(char), DEVICE_FILE_SIZE);
|
||||
if (links[linkNum] == NULL) {
|
||||
INIT_LOGE("Failed to allocate memory for link, err = %d", errno);
|
||||
break;
|
||||
}
|
||||
// If a block device without partition name.
|
||||
// For now, we will not create symbol link for it.
|
||||
if (!INVALIDSTRING(uevent->partitionName)) {
|
||||
if (snprintf_s(links[linkNum], DEVICE_FILE_SIZE, DEVICE_FILE_SIZE - 1,
|
||||
"/dev/block/platform/%s/by-name/%s", parent, uevent->partitionName) == -1) {
|
||||
INIT_LOGE("Failed to build link");
|
||||
break;
|
||||
}
|
||||
if (bus != NULL) {
|
||||
if (STRINGEQUAL(bus, "/sys/bus/platform")) {
|
||||
INIT_LOGD("Find a platform device: %s", parent);
|
||||
parent = FindPlatformDeviceName(parent);
|
||||
if (parent != NULL) {
|
||||
BuildDeviceSymbolLinks(links, linkNum, parent, uevent->partitionName);
|
||||
}
|
||||
linkNum++;
|
||||
}
|
||||
}
|
||||
loop:
|
||||
parent = dirname(parent);
|
||||
continue;
|
||||
}
|
||||
|
||||
links[linkNum] = NULL;
|
||||
return links;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user