+
+/* Mount using the loopback device. You can't use the generic
+ * do_mount call for this because the first parameter isn't a
+ * device.
+ */
+int
+do_mount_loop (const char *file, const char *mountpoint)
+{
+ int r;
+ char *buf, *mp;
+ char *error;
+
+ /* We have to prefix /sysroot on both the filename and the mountpoint. */
+ mp = sysroot_path (mountpoint);
+ if (!mp) {
+ reply_with_perror ("malloc");
+ return -1;
+ }
+
+ buf = sysroot_path (file);
+ if (!file) {
+ reply_with_perror ("malloc");
+ free (mp);
+ return -1;
+ }
+
+ r = command (NULL, &error, "mount", "-o", "loop", buf, mp, NULL);
+ free (mp);
+ free (buf);
+ if (r == -1) {
+ reply_with_error ("mount: %s on %s: %s", file, mountpoint, error);
+ free (error);
+ return -1;
+ }
+
+ return 0;
+}
+
+/* Specialized calls mkmountpoint and rmmountpoint are really
+ * variations on mkdir and rmdir which do no checking and (in the
+ * mkmountpoint case) set the root_mounted flag.
+ */
+int
+do_mkmountpoint (const char *path)
+{
+ int r;
+
+ /* NEED_ROOT (return -1); - we don't want this test for this call. */
+ ABS_PATH (path, return -1);
+
+ CHROOT_IN;
+ r = mkdir (path, 0777);
+ CHROOT_OUT;
+
+ if (r == -1) {
+ reply_with_perror ("mkmountpoint: %s", path);
+ return -1;
+ }
+
+ /* Set the flag so that filesystems can be mounted here,
+ * not just on /sysroot.
+ */
+ root_mounted = 1;
+
+ return 0;
+}
+
+int
+do_rmmountpoint (const char *path)
+{
+ int r;
+
+ /* NEED_ROOT (return -1); - we don't want this test for this call. */
+ ABS_PATH (path, return -1);
+
+ CHROOT_IN;
+ r = rmdir (path);
+ CHROOT_OUT;
+
+ if (r == -1) {
+ reply_with_perror ("rmmountpoint: %s", path);
+ return -1;
+ }
+
+ return 0;
+}