From 75dbadee24b0bd6b738093b66f8415a630692671 Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Mon, 11 Dec 2000 15:10:33 +0000 Subject: week-end stuff: now supports second stage as a ramdisk adds better device files handling (some in initrd, others dynamically created) better logging of detected IDE and SCSI devices --- mdk-stage1/mount.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) (limited to 'mdk-stage1/mount.c') diff --git a/mdk-stage1/mount.c b/mdk-stage1/mount.c index 9a5dfca55..ef0c0f676 100644 --- a/mdk-stage1/mount.c +++ b/mdk-stage1/mount.c @@ -30,16 +30,88 @@ #include "mount.h" +/* WARNING: this won't work if the argument is not /dev/ based */ +static int ensure_dev_exists(char *dev) +{ + int major, minor; + int type = S_IFBLK; /* my default type is block. don't forget to change for chars */ + char * name; + struct stat buf; + + name = &dev[5]; /* we really need that dev be passed as /dev/something.. */ + + if (!stat(dev, &buf)) + return 0; /* if the file already exists, we assume it's correct */ + + if (name[0] == 's' && name[1] == 'd') { + /* SCSI disks */ + major = 8; + minor = (name[2] - 'a') << 4; + if (name[3] && name[4]) + minor += 10 + (name[4] - '0'); + else if (name[3]) + minor += (name[3] - '0'); + } else if (name[0] == 'h' && name[1] == 'd') { + /* IDE disks/cd's */ + if (name[2] == 'a') + major = 3, minor = 0; + else if (name[2] == 'b') + major = 3, minor = 64; + else if (name[2] == 'c') + major = 22, minor = 0; + else if (name[2] == 'd') + major = 22, minor = 64; + else if (name[2] == 'e') + major = 33, minor = 0; + else if (name[2] == 'f') + major = 33, minor = 64; + else if (name[2] == 'g') + major = 34, minor = 0; + else if (name[2] == 'h') + major = 34, minor = 64; + else + return -1; + + if (name[3] && name[4]) + minor += 10 + (name[4] - '0'); + else if (name[3]) + minor += (name[3] - '0'); + } else if (name[0] == 's' && name[1] == 'c' && name[2] == 'd') { + /* SCSI cd's */ + major = 11; + minor = name[3] - '0'; + } else { + log_message("I don't know how to create device %s, please post bugreport to me!", dev); + return -1; + } + + if (mknod(dev, type | 0600, makedev(major, minor))) { + log_perror(dev); + return -1; + } + + return 0; +} + + +/* mounts, creating the device if needed+possible */ int my_mount(char *dev, char *location, char *fs) { unsigned long flags; char * opts = NULL; struct stat buf; + int rc; + + rc = ensure_dev_exists(dev); + + if (rc != 0) { + log_message("could not create required device file"); + return -1; + } log_message("mounting %s on %s as type %s", dev, location, fs); if (stat(location, &buf)) { - log_message("creating dir %s", location); if (mkdir(location, 0755)) { log_message("could not create location dir"); return -1; @@ -64,5 +136,10 @@ int my_mount(char *dev, char *location, char *fs) if (!strcmp(fs, "iso9660")) flags |= MS_RDONLY; - return mount(dev, location, fs, flags, opts); + rc = mount(dev, location, fs, flags, opts); + + if (rc != 0) + log_perror(dev); + + return rc; } -- cgit v1.2.1