From: Youngjae Cho Date: Mon, 24 Jul 2023 11:46:52 +0000 (+0900) Subject: libcommon: Add syscommon_is_mounted() X-Git-Tag: accepted/tizen/unified/20230726.163532^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=78b2e902742b129dc1bc580a75fc89febde186a4;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git libcommon: Add syscommon_is_mounted() syscmmon_is_mounted() checks whether the given path exists in /etc/mtab. Change-Id: I994c4190a069330403e5eb516eb6fef7f5d5404f Signed-off-by: Youngjae Cho --- diff --git a/include/libsyscommon/common.h b/include/libsyscommon/common.h index 7fd6f66..f6cd108 100644 --- a/include/libsyscommon/common.h +++ b/include/libsyscommon/common.h @@ -43,6 +43,13 @@ bool syscommon_is_emulator(void); */ bool syscommon_is_container(void); +/** + * @brief Check if the path is mounted + * + * @return true if the path is mounted, otherwise return false + */ +bool syscommon_is_mounted(const char *path); + #ifdef __cplusplus } #endif diff --git a/src/libcommon/common.c b/src/libcommon/common.c index 2e96f29..0a220c7 100644 --- a/src/libcommon/common.c +++ b/src/libcommon/common.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "shared/log.h" #include "libsyscommon/common.h" @@ -72,3 +73,29 @@ bool syscommon_is_container(void) return is_container; } + +bool syscommon_is_mounted(const char *path) +{ + bool ret = false; + struct mntent *mnt; + const char *table = "/etc/mtab"; + FILE *fp; + int len; + + fp = setmntent(table, "r"); + if (!fp) + return ret; + + len = strlen(path) + 1; + while (1) { + mnt = getmntent(fp); + if (mnt == NULL) + break; + if (!strncmp(mnt->mnt_dir, path, len)) { + ret = true; + break; + } + } + endmntent(fp); + return ret; +}