Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
21c0c34d
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
21c0c34d
编写于
12月 06, 2021
作者:
O
openharmony_ci
提交者:
Gitee
12月 06, 2021
浏览文件
操作
浏览文件
下载
差异文件
!183 fix:misc分区写成固定值,不利于其他平台适配
Merge pull request !183 from 熊磊/startup_init_lite1206
上级
824cfd6e
e795ffba
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
78 addition
and
48 deletion
+78
-48
interfaces/innerkits/fs_manager/BUILD.gn
interfaces/innerkits/fs_manager/BUILD.gn
+0
-1
interfaces/innerkits/fs_manager/fstab.c
interfaces/innerkits/fs_manager/fstab.c
+48
-1
interfaces/innerkits/include/fs_manager/fs_manager.h
interfaces/innerkits/include/fs_manager/fs_manager.h
+2
-1
services/include/init_utils.h
services/include/init_utils.h
+2
-1
services/init/standard/init_reboot.c
services/init/standard/init_reboot.c
+26
-44
未找到文件。
interfaces/innerkits/fs_manager/BUILD.gn
浏览文件 @
21c0c34d
...
...
@@ -24,7 +24,6 @@ fs_manager_include_dirs = [
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/log",
]
fs_manager_deps = [
...
...
interfaces/innerkits/fs_manager/fstab.c
浏览文件 @
21c0c34d
...
...
@@ -289,6 +289,53 @@ FstabItem *FindFstabItemForPath(Fstab fstab, const char *path)
return
item
;
}
char
*
GetFstabFile
(
void
)
{
char
file
[
PATH_MAX
]
=
{
0
};
if
(
InUpdaterMode
()
==
1
)
{
if
(
strncpy_s
(
file
,
PATH_MAX
,
"/etc/fstab.updater"
,
strlen
(
"/etc/fstab.updater"
))
!=
0
)
{
FSMGR_LOGE
(
"Failed strncpy_s err=%d"
,
errno
);
return
NULL
;
}
}
else
{
char
hardware
[
MAX_BUFFER_LEN
]
=
{
0
};
char
*
buffer
=
ReadFileData
(
"/proc/cmdline"
);
if
(
buffer
==
NULL
)
{
FSMGR_LOGE
(
"Failed read
\"
/proc/cmdline
\"
"
);
return
NULL
;
}
int
ret
=
GetProcCmdlineValue
(
"hardware"
,
buffer
,
hardware
,
MAX_BUFFER_LEN
);
free
(
buffer
);
if
(
ret
!=
0
)
{
FSMGR_LOGE
(
"Failed get hardware from cmdline"
);
return
NULL
;
}
if
(
snprintf_s
(
file
,
PATH_MAX
,
PATH_MAX
-
1
,
"/vendor/etc/fstab.%s"
,
hardware
)
==
-
1
)
{
FSMGR_LOGE
(
"Fail snprintf_s err=%d"
,
errno
);
return
NULL
;
}
}
FSMGR_LOGI
(
"file is %s"
,
file
);
return
strdup
(
file
);
// After the return value is used up, it must be free.
}
int
GetBlockDeviceByMountPoint
(
const
char
*
mountPoint
,
const
Fstab
*
fstab
,
char
*
deviceName
,
int
nameLen
)
{
if
(
fstab
==
NULL
||
mountPoint
==
NULL
||
*
mountPoint
==
'\0'
||
deviceName
==
NULL
)
{
return
-
1
;
}
FstabItem
*
item
=
FindFstabItemForMountPoint
(
*
fstab
,
mountPoint
);
if
(
item
==
NULL
)
{
FSMGR_LOGE
(
"Failed get fstab item from point
\"
%s
\"
"
,
mountPoint
);
return
-
1
;
}
if
(
strncpy_s
(
deviceName
,
nameLen
,
item
->
deviceName
,
strlen
(
item
->
deviceName
))
!=
0
)
{
FSMGR_LOGE
(
"Failed strncpy_s err=%d"
,
errno
);
return
-
1
;
}
return
0
;
}
static
const
struct
MountFlags
mountFlags
[]
=
{
{
"noatime"
,
MS_NOATIME
},
{
"noexec"
,
MS_NOEXEC
},
...
...
@@ -383,4 +430,4 @@ unsigned long GetMountFlags(char *mountFlag, char *fsSpecificData, size_t fsSpec
#if __cplusplus
}
#endif
#endif
\ No newline at end of file
#endif
interfaces/innerkits/include/fs_manager/fs_manager.h
浏览文件 @
21c0c34d
...
...
@@ -60,7 +60,8 @@ 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
);
char
*
GetFstabFile
(
void
);
int
GetBlockDeviceByMountPoint
(
const
char
*
mountPoint
,
const
Fstab
*
fstab
,
char
*
deviceName
,
int
nameLen
);
bool
IsSupportedFilesystem
(
const
char
*
fsType
);
int
DoFormat
(
const
char
*
devPath
,
const
char
*
fsType
);
int
MountOneItem
(
FstabItem
*
item
);
...
...
services/include/init_utils.h
浏览文件 @
21c0c34d
...
...
@@ -29,12 +29,13 @@ extern "C" {
#define OCTAL_BASE 8
#define DECIMAL_BASE 10
#define WAIT_MAX_COUNT 10
#define MAX_BUFFER_LEN 256
#define ARRAY_LENGTH(array) (sizeof((array)) / sizeof((array)[0]))
uid_t
DecodeUid
(
const
char
*
name
);
char
*
ReadFileToBuf
(
const
char
*
configFile
);
int
GetProcCmdlineValue
(
const
char
*
name
,
const
char
*
buffer
,
char
*
value
,
int
length
);
char
*
ReadFileData
(
const
char
*
fileName
);
int
SplitString
(
char
*
srcPtr
,
const
char
*
del
,
char
**
dstPtr
,
int
maxNum
);
void
WaitForFile
(
const
char
*
source
,
unsigned
int
maxCount
);
size_t
WriteAll
(
int
fd
,
const
char
*
buffer
,
size_t
size
);
...
...
services/init/standard/init_reboot.c
浏览文件 @
21c0c34d
...
...
@@ -13,11 +13,12 @@
* limitations under the License.
*/
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/reboot.h>
#include <sys/syscall.h>
#include "fs_manager/fs_manager.h"
#include "init_log.h"
#include "init_service.h"
#include "init_service_manager.h"
...
...
@@ -28,10 +29,6 @@
#define MAX_COMMAND_SIZE 20
#define MAX_UPDATE_SIZE 100
#define REBOOT_MAGIC1 0xfee1dead
#define REBOOT_MAGIC2 672274793
#define REBOOT_CMD_RESTART2 0xA1B2C3D4
struct
RBMiscUpdateMessage
{
char
command
[
MAX_COMMAND_SIZE
];
char
update
[
MAX_UPDATE_SIZE
];
...
...
@@ -43,16 +40,16 @@ static int RBMiscWriteUpdaterMessage(const char *path, const struct RBMiscUpdate
INIT_CHECK_RETURN_VALUE
(
realPath
!=
NULL
,
-
1
);
int
ret
=
0
;
FILE
*
fp
=
fopen
(
realPath
,
"rb+"
);
free
(
realPath
);
realPath
=
NULL
;
if
(
fp
!=
NULL
)
{
size_t
writeLen
=
fwrite
(
boot
,
sizeof
(
struct
RBMiscUpdateMessage
),
1
,
fp
);
INIT_ERROR_CHECK
(
writeLen
==
1
,
ret
=
-
1
,
"Failed to write misc for reboot"
);
(
void
)
fclose
(
fp
);
}
else
{
ret
=
-
1
;
INIT_LOGE
(
"Failed to open %s"
,
path
);
}
free
(
realPath
);
realPath
=
NULL
;
(
void
)
fclose
(
fp
);
return
ret
;
}
...
...
@@ -62,46 +59,24 @@ static int RBMiscReadUpdaterMessage(const char *path, struct RBMiscUpdateMessage
INIT_CHECK_RETURN_VALUE
(
realPath
!=
NULL
,
-
1
);
int
ret
=
0
;
FILE
*
fp
=
fopen
(
realPath
,
"rb"
);
free
(
realPath
);
realPath
=
NULL
;
if
(
fp
!=
NULL
)
{
size_t
readLen
=
fread
(
boot
,
1
,
sizeof
(
struct
RBMiscUpdateMessage
),
fp
);
INIT_ERROR_CHECK
(
readLen
>
0
,
ret
=
-
1
,
"Failed to read misc for reboot"
);
(
void
)
fclose
(
fp
);
}
else
{
ret
=
-
1
;
INIT_LOGE
(
"Failed to open %s"
,
path
);
}
return
ret
;
}
static
int
GetMountStatusForMountPoint
(
const
char
*
mountPoint
)
{
const
int
bufferMaxSize
=
512
;
char
buffer
[
bufferMaxSize
];
size_t
n
;
const
char
*
mountFile
=
"/proc/mounts"
;
FILE
*
fp
=
fopen
(
mountFile
,
"r"
);
INIT_CHECK_RETURN_VALUE
(
fp
!=
NULL
,
1
);
while
(
fgets
(
buffer
,
sizeof
(
buffer
)
-
1
,
fp
)
!=
NULL
)
{
n
=
strlen
(
buffer
);
if
(
buffer
[
n
-
1
]
==
'\n'
)
{
buffer
[
n
-
1
]
=
'\0'
;
}
if
(
strstr
(
buffer
,
mountPoint
)
!=
NULL
)
{
(
void
)
fclose
(
fp
);
return
1
;
}
}
free
(
realPath
);
realPath
=
NULL
;
(
void
)
fclose
(
fp
);
return
0
;
return
ret
;
}
static
int
CheckAndRebootToUpdater
(
const
char
*
valueData
,
const
char
*
cmd
,
const
char
*
cmdExt
,
const
char
*
boot
)
static
int
CheckAndRebootToUpdater
(
const
char
*
valueData
,
const
char
*
cmd
,
const
char
*
cmdExt
,
const
char
*
boot
,
const
char
*
miscFile
)
{
// "updater" or "updater:"
const
char
*
miscFile
=
"/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc"
;
struct
RBMiscUpdateMessage
msg
;
int
ret
=
RBMiscReadUpdaterMessage
(
miscFile
,
&
msg
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to get misc info for %s."
,
cmd
);
...
...
@@ -141,7 +116,7 @@ static int CheckRebootParam(const char *valueData)
return
0
;
}
static
const
char
*
cmdParams
[]
=
{
"shutdown"
,
"updater"
,
"updater:"
,
"flash"
,
"flash:"
,
"NoArgument"
,
"loader"
,
"bootloader"
"shutdown"
,
"updater"
,
"updater:"
,
"flash"
,
"flash:"
,
"NoArgument"
,
"loader"
,
"bootloader"
};
size_t
i
=
0
;
for
(;
i
<
ARRAY_LENGTH
(
cmdParams
);
i
++
)
{
...
...
@@ -164,7 +139,16 @@ void ExecReboot(const char *value)
return
;
}
INIT_ERROR_CHECK
(
CheckRebootParam
(
valueData
)
==
0
,
return
,
"Invalid arg %s for reboot."
,
value
);
char
*
fstabFile
=
GetFstabFile
();
INIT_ERROR_CHECK
(
fstabFile
!=
NULL
,
return
,
"Failed get fstab file"
);
Fstab
*
fstab
=
NULL
;
INIT_ERROR_CHECK
((
fstab
=
ReadFstabFromFile
(
fstabFile
,
false
))
!=
NULL
,
free
(
fstabFile
);
return
,
"Failed get fstab from %s"
,
fstabFile
);
free
(
fstabFile
);
char
miscDevice
[
PATH_MAX
]
=
{
0
};
int
ret
=
GetBlockDeviceByMountPoint
(
"/misc"
,
fstab
,
miscDevice
,
PATH_MAX
);
ReleaseFstab
(
fstab
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
,
"Failed to get misc device name."
);
StopAllServices
(
SERVICE_ATTR_INVALID
);
sync
();
INIT_CHECK_ONLY_ELOG
(
GetMountStatusForMountPoint
(
"/vendor"
)
==
0
||
umount
(
"/vendor"
)
==
0
,
...
...
@@ -177,23 +161,21 @@ void ExecReboot(const char *value)
INIT_LOGE
(
"Failed to get mount point
\"
/data
\"
"
);
}
int
ret
=
0
;
ret
=
0
;
if
(
valueData
==
NULL
)
{
ret
=
CheckAndRebootToUpdater
(
NULL
,
"reboot"
,
NULL
,
NULL
);
ret
=
CheckAndRebootToUpdater
(
NULL
,
"reboot"
,
NULL
,
NULL
,
miscDevice
);
}
else
if
(
strcmp
(
valueData
,
"shutdown"
)
==
0
)
{
#ifndef STARTUP_INIT_TEST
ret
=
reboot
(
RB_POWER_OFF
);
#endif
}
else
if
(
strcmp
(
valueData
,
"bootloader"
)
==
0
)
{
#ifndef STARTUP_INIT_TEST
ret
=
reboot
(
RB_POWER_OFF
);
ret
=
reboot
(
RB_POWER_OFF
);
#endif
}
else
if
(
strncmp
(
valueData
,
"updater"
,
strlen
(
"updater"
))
==
0
)
{
ret
=
CheckAndRebootToUpdater
(
valueData
,
"updater"
,
"updater:"
,
"boot_updater"
);
ret
=
CheckAndRebootToUpdater
(
valueData
,
"updater"
,
"updater:"
,
"boot_updater"
,
miscDevice
);
}
else
if
(
strncmp
(
valueData
,
"flash"
,
strlen
(
"flash"
))
==
0
)
{
ret
=
CheckAndRebootToUpdater
(
valueData
,
"flash"
,
"flash:"
,
"boot_flash"
);
}
else
if
(
strncmp
(
valueData
,
"loader"
,
strlen
(
"loader"
))
==
0
)
{
syscall
(
__NR_reboot
,
REBOOT_MAGIC1
,
REBOOT_MAGIC2
,
REBOOT_CMD_RESTART2
,
"loader"
);
ret
=
CheckAndRebootToUpdater
(
valueData
,
"flash"
,
"flash:"
,
"boot_flash"
,
miscDevice
);
}
INIT_LOGI
(
"Reboot %s %s."
,
value
,
(
ret
==
0
)
?
"success"
:
"fail"
);
return
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录