summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/lomount.c
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2001-01-11 19:11:41 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2001-01-11 19:11:41 +0000
commit607ee5d94e09cb06d8338c6862c29eb538699b69 (patch)
tree58ad7097fb3b79424846d4d6fd75cd7857cf6584 /mdk-stage1/lomount.c
parent2bcc4dd71658524b19f6a59a7a16c2542c3fcf3e (diff)
downloaddrakx-607ee5d94e09cb06d8338c6862c29eb538699b69.tar
drakx-607ee5d94e09cb06d8338c6862c29eb538699b69.tar.gz
drakx-607ee5d94e09cb06d8338c6862c29eb538699b69.tar.bz2
drakx-607ee5d94e09cb06d8338c6862c29eb538699b69.tar.xz
drakx-607ee5d94e09cb06d8338c6862c29eb538699b69.zip
- add DISK install from ISO image file
Diffstat (limited to 'mdk-stage1/lomount.c')
-rw-r--r--mdk-stage1/lomount.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/mdk-stage1/lomount.c b/mdk-stage1/lomount.c
new file mode 100644
index 000000000..7150694d1
--- /dev/null
+++ b/mdk-stage1/lomount.c
@@ -0,0 +1,170 @@
+/*
+ * Guillaume Cottenceau (gc@mandrakesoft.com)
+ *
+ * Copyright 2000 MandrakeSoft
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/* This code comes from util-linux-2.10n (mount/lomount.c)
+ * (this is a simplified version of this code)
+ */
+
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "stage1.h"
+#include "frontend.h"
+#include "log.h"
+#include "mount.h"
+#include "modules.h"
+
+#include "lomount.h"
+
+
+#define LO_NAME_SIZE 64
+#define LO_KEY_SIZE 32
+
+struct loop_info
+{
+ int lo_number; /* ioctl r/o */
+ dev_t lo_device; /* ioctl r/o */
+ unsigned long lo_inode; /* ioctl r/o */
+ dev_t lo_rdevice; /* ioctl r/o */
+ int lo_offset;
+ int lo_encrypt_type;
+ int lo_encrypt_key_size; /* ioctl w/o */
+ int lo_flags; /* ioctl r/o */
+ char lo_name[LO_NAME_SIZE];
+ unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
+ unsigned long lo_init[2];
+ char reserved[4];
+};
+
+#define LOOP_SET_FD 0x4C00
+#define LOOP_CLR_FD 0x4C01
+#define LOOP_SET_STATUS 0x4C02
+#define LOOP_GET_STATUS 0x4C03
+
+int
+set_loop (const char *device, const char *file)
+{
+ struct loop_info loopinfo;
+ int fd, ffd, mode;
+
+ mode = O_RDONLY;
+
+ if ((ffd = open (file, mode)) < 0)
+ return 1;
+
+ if ((fd = open (device, mode)) < 0)
+ return 1;
+
+ memset(&loopinfo, 0, sizeof (loopinfo));
+ strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
+ loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
+ loopinfo.lo_offset = 0;
+
+#ifdef MCL_FUTURE
+ /*
+ * Oh-oh, sensitive data coming up. Better lock into memory to prevent
+ * passwd etc being swapped out and left somewhere on disk.
+ */
+
+ if(mlockall(MCL_CURRENT|MCL_FUTURE)) {
+ log_message("%s (memlock)\n", strerror(errno));
+ log_message("CRITICAL Couldn't lock into memory!\n");
+ return 1;
+ }
+#endif
+
+ if (ioctl(fd, LOOP_SET_FD, ffd) < 0)
+ return 1;
+
+ if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
+ (void) ioctl (fd, LOOP_CLR_FD, 0);
+ return 1;
+ }
+
+ close(fd);
+ close(ffd);
+ return 0;
+}
+
+int
+del_loop (const char *device)
+{
+ int fd;
+
+ if ((fd = open (device, O_RDONLY)) < 0)
+ return 1;
+
+ if (ioctl (fd, LOOP_CLR_FD, 0) < 0)
+ return 1;
+
+ close (fd);
+ return 0;
+}
+
+
+char * loopdev = "/dev/loop3"; /* Ugly. But do I care? */
+
+int
+lomount(char *loopfile, char *where)
+{
+
+ long int flag;
+
+ flag = MS_MGC_VAL;
+ flag |= MS_RDONLY;
+
+ if (my_insmod("loop", ANY_DRIVER_TYPE, NULL)) {
+ log_message("can't lomount without loop.o kernel driver");
+ return 1;
+ }
+
+ if (set_loop(loopdev, loopfile)) {
+ log_message("set_loop failed on %s (%s)\n", loopdev, strerror(errno));
+ return 1;
+ }
+
+ if (my_mount(loopdev, where, "iso9660")) {
+ log_message("mount failed: %s\n", strerror(errno));
+ del_loop(loopdev);
+ return 1;
+ }
+
+ log_message("lomount succeded for %s on %s\n", loopfile, where);
+ return 0;
+}
+
+
+int
+loumount()
+{
+ if (umount(loopdev)) {
+ log_perror("loumount");
+ return 1;
+ }
+
+ if (del_loop(loopdev)) {
+ log_perror("del_loop");
+ return 1;
+ }
+ return 0;
+}
+
+