+/* You must mount something on "/" first before many operations.
+ * Hence we have an internal function which can test if something is
+ * mounted on *or under* the sysroot directory. (It has to be *or
+ * under* because of mkmountpoint and friends).
+ */
+int
+is_root_mounted (void)
+{
+ FILE *fp;
+ struct mntent *m;
+
+ /* NB: Eventually we should aim to parse /proc/self/mountinfo, but
+ * that requires custom parsing code.
+ */
+ fp = setmntent ("/proc/mounts", "r");
+ if (fp == NULL) {
+ perror ("/proc/mounts");
+ exit (EXIT_FAILURE);
+ }
+
+ while ((m = getmntent (fp)) != NULL) {
+ /* Allow a mount directory like "/sysroot". */
+ if (sysroot_len > 0 && STREQ (m->mnt_dir, sysroot)) {
+ gotit:
+ endmntent (fp);
+ return 1;
+ }
+ /* Or allow a mount directory like "/sysroot/...". */
+ if (STRPREFIX (m->mnt_dir, sysroot) && m->mnt_dir[sysroot_len] == '/')
+ goto gotit;
+ }
+
+ endmntent (fp);
+ return 0;
+}