+ mounted = true;
+#else
+ struct statvfs buf;
+
+ if (statvfs(path, &buf) == -1) {
+ /* If statvfs errors, e.g., due to the path not existing,
+ * we consider the device not mounted. */
+ mounted = false;
+ } else {
+ char *sanitized = sstrdup(path);
+ if (strlen(sanitized) > 1 && sanitized[strlen(sanitized) - 1] == '/')
+ sanitized[strlen(sanitized) - 1] = '\0';