mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-26 18:01:03 +00:00
优化remount命令
Signed-off-by: ohxianzhi <duxianzhi@huawei.com> Change-Id: I22a3d5e7951de777b1445b1607ce65722837a214
This commit is contained in:
parent
0e17cb86e1
commit
b7cb50d3e9
@ -66,7 +66,7 @@ bool CheckIsExt4(const char *dev, uint64_t offset)
|
||||
}
|
||||
|
||||
if (superBlock.s_magic == EXT4_SUPER_MAGIC) {
|
||||
BEGET_LOGE("this [dev] %s is ext4:[block cout]: %d, [size]: %d", dev,
|
||||
BEGET_LOGI("this [dev] %s is ext4:[block cout]: %d, [size]: %d", dev,
|
||||
superBlock.s_blocks_count_lo, (superBlock.s_blocks_count_lo * BLOCK_SIZE_UNIT));
|
||||
close(fd);
|
||||
return true;
|
||||
|
@ -36,14 +36,12 @@ int GetRemountResult(void)
|
||||
close(fd);
|
||||
if (buff[0] == '0' + REMOUNT_SUCC) {
|
||||
return REMOUNT_SUCC;
|
||||
} else {
|
||||
return REMOUNT_FAIL;
|
||||
}
|
||||
}
|
||||
return REMOUNT_NONE;
|
||||
return REMOUNT_FAIL;
|
||||
}
|
||||
|
||||
void SetRemountResultFlag(bool result)
|
||||
void SetRemountResultFlag()
|
||||
{
|
||||
struct stat st;
|
||||
int ret;
|
||||
@ -64,11 +62,7 @@ void SetRemountResultFlag(bool result)
|
||||
}
|
||||
|
||||
char buff[1];
|
||||
if (result) {
|
||||
buff[0] = '0' + REMOUNT_SUCC;
|
||||
} else {
|
||||
buff[0] = '0' + REMOUNT_FAIL;
|
||||
}
|
||||
buff[0] = '0' + REMOUNT_SUCC;
|
||||
|
||||
ret = write(fd, buff, 1);
|
||||
if (ret < 0) {
|
||||
|
@ -33,13 +33,12 @@ extern "C" {
|
||||
#define REMOUNT_RESULT_PATH STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/"
|
||||
#define REMOUNT_RESULT_FLAG STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/remount.result.done"
|
||||
|
||||
#define REMOUNT_NONE 0
|
||||
#define REMOUNT_SUCC 1
|
||||
#define REMOUNT_FAIL 2
|
||||
#define REMOUNT_SUCC 0
|
||||
#define REMOUNT_FAIL 1
|
||||
|
||||
int GetRemountResult(void);
|
||||
|
||||
void SetRemountResultFlag(bool result);
|
||||
void SetRemountResultFlag();
|
||||
|
||||
int RemountOverlay(void);
|
||||
|
||||
|
@ -24,7 +24,7 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool RemountRofsOverlay();
|
||||
int RemountRofsOverlay();
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -25,9 +25,9 @@ int main(int argc, const char *argv[])
|
||||
#ifdef EROFS_OVERLAY
|
||||
EnableInitLog(INIT_INFO);
|
||||
if (getuid() == 0 && IsOverlayEnable()) {
|
||||
bool ret = RemountRofsOverlay();
|
||||
printf("remount %s\n", ret ? "success" : "failed");
|
||||
return ret ? 0 : 1;
|
||||
int ret = RemountRofsOverlay();
|
||||
printf("remount %s\n", ret == REMOUNT_SUCC ? "success" : "failed");
|
||||
return ret;
|
||||
}
|
||||
printf("not need erofs overlay, remount success\n");
|
||||
#endif
|
||||
|
@ -157,7 +157,7 @@ INIT_STATIC void OverlayRemountPost(const char *mnt)
|
||||
}
|
||||
}
|
||||
|
||||
INIT_STATIC bool DoRemount(struct mntent *mentry, bool *result)
|
||||
INIT_STATIC bool DoRemount(struct mntent *mentry)
|
||||
{
|
||||
int devNum = 0;
|
||||
char *mnt = NULL;
|
||||
@ -207,7 +207,6 @@ INIT_STATIC bool DoRemount(struct mntent *mentry, bool *result)
|
||||
return false;
|
||||
}
|
||||
OverlayRemountPost(mnt);
|
||||
*result = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -255,7 +254,7 @@ int RootOverlaySetup(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
INIT_STATIC bool DoSystemRemount(struct mntent *mentry, bool *result)
|
||||
INIT_STATIC bool DoSystemRemount(struct mntent *mentry)
|
||||
{
|
||||
int devNum = 0;
|
||||
int ret = 0;
|
||||
@ -292,7 +291,6 @@ INIT_STATIC bool DoSystemRemount(struct mntent *mentry, bool *result)
|
||||
return false;
|
||||
}
|
||||
|
||||
*result = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -390,19 +388,18 @@ static void EngFilesOverlay(const char *source, const char *target)
|
||||
dir = NULL;
|
||||
}
|
||||
|
||||
bool RemountRofsOverlay()
|
||||
int RemountRofsOverlay()
|
||||
{
|
||||
bool result = false;
|
||||
int lastRemountResult = GetRemountResult();
|
||||
INIT_LOGI("get last remount result is %d.", lastRemountResult);
|
||||
if (lastRemountResult != REMOUNT_NONE) {
|
||||
return (lastRemountResult == REMOUNT_SUCC) ? true : false;
|
||||
if (lastRemountResult == REMOUNT_SUCC) {
|
||||
return REMOUNT_SUCC;
|
||||
}
|
||||
FILE *fp;
|
||||
struct mntent *mentry = NULL;
|
||||
if ((fp = setmntent("/proc/mounts", "r")) == NULL) {
|
||||
INIT_LOGE("Failed to open /proc/mounts.");
|
||||
return false;
|
||||
return REMOUNT_FAIL;
|
||||
}
|
||||
|
||||
while (NULL != (mentry = getmntent(fp))) {
|
||||
@ -412,23 +409,27 @@ bool RemountRofsOverlay()
|
||||
}
|
||||
|
||||
if (strcmp(mentry->mnt_dir, ROOT_MOUNT_DIR) == 0) {
|
||||
DoSystemRemount(mentry, &result);
|
||||
if (!DoSystemRemount(mentry)) {
|
||||
endmntent(fp);
|
||||
INIT_LOGE("do system remount failed on %s", mentry->mnt_dir);
|
||||
return REMOUNT_FAIL;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
INIT_LOGI("do remount %s", mentry->mnt_dir);
|
||||
if (!DoRemount(mentry, &result)) {
|
||||
if (!DoRemount(mentry)) {
|
||||
endmntent(fp);
|
||||
INIT_LOGE("do remount failed on %s", mentry->mnt_dir);
|
||||
return false;
|
||||
return REMOUNT_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
endmntent(fp);
|
||||
SetRemountResultFlag(result);
|
||||
SetRemountResultFlag();
|
||||
|
||||
INIT_LOGI("remount system overlay...");
|
||||
EngFilesOverlay("/eng_system", "/");
|
||||
INIT_LOGI("remount chipset overlay...");
|
||||
EngFilesOverlay("/eng_chipset", "/chipset");
|
||||
return true;
|
||||
return REMOUNT_SUCC;
|
||||
}
|
@ -32,11 +32,10 @@ HWTEST_F(ErofsRemountUnitTest, Init_GetRemountResult_001, TestSize.Level0)
|
||||
{
|
||||
const char *cmdLine;
|
||||
rmdir(REMOUNT_RESULT_PATH);
|
||||
SetRemountResultFlag(true);
|
||||
SetRemountResultFlag();
|
||||
|
||||
CheckAndCreateDir(REMOUNT_RESULT_FLAG);
|
||||
SetRemountResultFlag(false);
|
||||
SetRemountResultFlag(true);
|
||||
SetRemountResultFlag();
|
||||
rmdir(REMOUNT_RESULT_PATH);
|
||||
}
|
||||
|
||||
|
@ -107,9 +107,9 @@ int GetDevSize(const char *fsBlkDev, uint64_t *devSize);
|
||||
int FormatExt4(const char *fsBlkDev, const char *fsMntPoint);
|
||||
void OverlayRemountPre(const char *mnt);
|
||||
void OverlayRemountPost(const char *mnt);
|
||||
bool DoRemount(struct mntent *mentry, bool *result);
|
||||
bool DoRemount(struct mntent *mentry);
|
||||
bool DirectoryExists(const char *path);
|
||||
bool DoSystemRemount(struct mntent *mentry, bool *result);
|
||||
bool DoSystemRemount(struct mntent *mentry);
|
||||
|
||||
//remount
|
||||
int Modem2Exchange(const char *modemPath, const char *exchangePath);
|
||||
|
Loading…
Reference in New Issue
Block a user