syscmmon_is_mounted() checks whether the given path exists in /etc/mtab.
Change-Id: I994c4190a069330403e5eb516eb6fef7f5d5404f
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
*/
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
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#include <mntent.h>
#include <system_info.h>
#include "shared/log.h"
#include "libsyscommon/common.h"
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;
+}