diff options
Diffstat (limited to 'mdk-stage1/mount.c')
-rw-r--r-- | mdk-stage1/mount.c | 118 |
1 files changed, 21 insertions, 97 deletions
diff --git a/mdk-stage1/mount.c b/mdk-stage1/mount.c index fd86a13b7..14b2b2fc2 100644 --- a/mdk-stage1/mount.c +++ b/mdk-stage1/mount.c @@ -1,7 +1,7 @@ /* - * Guillaume Cottenceau (gc@mandrakesoft.com) + * Guillaume Cottenceau (gc) * - * Copyright 2000 MandrakeSoft + * Copyright 2000 Mandriva * * This software may be freely redistributed under the terms of the GNU * public license. @@ -19,6 +19,9 @@ * */ +// for asprintf: +#define _GNU_SOURCE +#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> @@ -26,107 +29,40 @@ #include <sys/stat.h> #include <sys/types.h> #include "log.h" +#include "utils.h" #include "modules.h" #include "mount.h" -#ifndef DISABLE_MEDIAS /* WARNING: this won't work if the argument is not /dev/ based */ -int ensure_dev_exists(char *dev) +int ensure_dev_exists(const 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; - char * ptr; - 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 (ptr_begins_static_str(name, "sd")) { - /* 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 (ptr_begins_static_str(name, "hd")) { - /* 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 (ptr_begins_static_str(name , "sr")) { - /* SCSI cd's */ - major = 11; - minor = name[2] - '0'; - } else if (ptr_begins_static_str(name, "ida/") || - ptr_begins_static_str(name, "cciss/")) { - /* Compaq Smart Array "ida/c0d0{p1}" */ - ptr = strchr(name, '/'); - mkdir("/dev/ida", 0755); - mkdir("/dev/cciss", 0755); - major = ptr_begins_static_str(name, "ida/") ? 72 : 104 + charstar_to_int(ptr+2); - ptr = strchr(ptr, 'd'); - minor = 16 * charstar_to_int(ptr+1); - ptr = strchr(ptr, 'p'); - minor += charstar_to_int(ptr+1); - } else if (ptr_begins_static_str(name, "rd/")) { - /* DAC960 "rd/cXdXXpX" */ - mkdir("/dev/rd", 0755); - major = 48 + charstar_to_int(name+4); - ptr = strchr(name+4, 'd'); - minor = 8 * charstar_to_int(ptr+1); - ptr = strchr(ptr, 'p'); - minor += charstar_to_int(ptr+1); - } else { - log_message("I don't know how to create device %s, please post bugreport to me!", dev); - return -1; - } + // give udev some time to create nodes if module was just insmoded: + system("udevadm settle"); - if (mknod(dev, type | 0600, makedev(major, minor))) { - log_perror(dev); + if (!stat(dev, &buf)) { + log_message("I don't know how to create device %s, please post bugreport to me!", dev); return -1; } return 0; } -#endif /* DISABLE_MEDIAS */ /* mounts, creating the device if needed+possible */ int my_mount(char *dev, char *location, char *fs, int force_rw) { - unsigned long flags = MS_MGC_VAL | (force_rw ? 0 : MS_RDONLY); char * opts = NULL; struct stat buf; int rc; -#ifndef DISABLE_MEDIAS if (strcmp(fs, "nfs")) { rc = ensure_dev_exists(dev); if (rc != 0) { @@ -134,7 +70,6 @@ int my_mount(char *dev, char *location, char *fs, int force_rw) return -1; } } -#endif log_message("mounting %s on %s as type %s", dev, location, fs); @@ -156,30 +91,19 @@ int my_mount(char *dev, char *location, char *fs, int force_rw) } #ifndef DISABLE_MEDIAS - if (!strcmp(fs, "vfat")) { - my_insmod("vfat", ANY_DRIVER_TYPE, NULL); + if (!strcmp(fs, "nfs")) + opts = "nolock"; + if (!strcmp(fs, "vfat")) opts = "check=relaxed"; - } - - if (!strcmp(fs, "reiserfs")) - my_insmod("reiserfs", ANY_DRIVER_TYPE, NULL); - - if (!strcmp(fs, "iso9660")) - my_insmod("isofs", ANY_DRIVER_TYPE, NULL); #endif - -#ifndef DISABLE_NETWORK - if (!strcmp(fs, "nfs")) { - int flags = MS_RDONLY; - my_insmod("nfs", ANY_DRIVER_TYPE, NULL); - log_message("preparing nfsmount for %s", dev); - rc = nfsmount_prepare(dev, &flags, &opts); - if (rc != 0) - return rc; + char *cmd; + rc = asprintf(&cmd, "mount %s %s -t %s -o %s%s > /dev/null 2>&1", dev, location, fs, (force_rw ? "" : "ro,"), (opts ? opts : "")); + if (rc == -1) { + log_perror("asprint allocation failure"); + rmdir(location); + return rc; } -#endif - - rc = mount(dev, location, fs, flags, opts); + rc = system(cmd); if (rc != 0) { log_perror("mount failed"); rmdir(location); |