From b7cb50d3e90a2980e879e87dc6d50af83da8c179 Mon Sep 17 00:00:00 2001 From: ohxianzhi Date: Wed, 30 Oct 2024 17:34:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96remount=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ohxianzhi Change-Id: I22a3d5e7951de777b1445b1607ce65722837a214 --- .../erofs_overlay/erofs_overlay_common.c | 2 +- .../erofs_overlay/erofs_remount_overlay.c | 12 ++------ .../include/erofs_remount_overlay.h | 7 ++--- remount/include/remount_overlay.h | 2 +- remount/remount.c | 6 ++-- remount/remount_overlay.c | 29 ++++++++++--------- .../erofs/erofs_remount_unittest.cpp | 5 ++-- test/unittest/param/param_stub.h | 4 +-- 8 files changed, 30 insertions(+), 37 deletions(-) diff --git a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_overlay_common.c b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_overlay_common.c index f3c1b35c3..775292019 100644 --- a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_overlay_common.c +++ b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_overlay_common.c @@ -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; diff --git a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c index 0ffe97646..da52dd2ee 100644 --- a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c +++ b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c @@ -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) { diff --git a/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h b/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h index 6f3e9df7c..99f6e3102 100644 --- a/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h +++ b/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h @@ -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); diff --git a/remount/include/remount_overlay.h b/remount/include/remount_overlay.h index 09f72b184..fedf4a229 100644 --- a/remount/include/remount_overlay.h +++ b/remount/include/remount_overlay.h @@ -24,7 +24,7 @@ extern "C" { #endif #endif -bool RemountRofsOverlay(); +int RemountRofsOverlay(); #ifdef __cplusplus #if __cplusplus diff --git a/remount/remount.c b/remount/remount.c index 7861b74dc..b4942a4c0 100644 --- a/remount/remount.c +++ b/remount/remount.c @@ -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 diff --git a/remount/remount_overlay.c b/remount/remount_overlay.c index c4d16b6e0..a214d2a5a 100644 --- a/remount/remount_overlay.c +++ b/remount/remount_overlay.c @@ -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; } \ No newline at end of file diff --git a/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp b/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp index 8450f8fb4..5aa78a53e 100644 --- a/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp +++ b/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp @@ -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); } diff --git a/test/unittest/param/param_stub.h b/test/unittest/param/param_stub.h index 5c42038a0..0beeed841 100644 --- a/test/unittest/param/param_stub.h +++ b/test/unittest/param/param_stub.h @@ -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);