Beispiel #1
0
static int
mountRocksDevice (char *device, int major, int minor, char *marker)
{
	mode_t	mode;
	char	devicepath[128];
	char	markerpath[128];
	char 	*fstype[10];
	char	*mountpoint = "/mnt/rocks-disk";
	int 	rc, i=0;

	if (ignoreCert())
		return 1;
		
	sprintf(devicepath, "/tmp/rocks-%s", device);

	mode = S_IFBLK | S_IRUSR | S_IWUSR;

	if (mknod(devicepath, mode, makedev(major, minor)) < 0) {
		logMessage(ERROR, "mountRocksDevice:mknod failed: %s",
			strerror(errno));
		return 1;
	}

	mkdirChain(mountpoint);

	/* Mount the partition. I dont like this exhaustive search. */

	fstype[i++] = "ext3";
	fstype[i++] = "ext2";
	fstype[i++] = "vfat";
	fstype[i++] = "xfs";
	fstype[i++] = 0;

	for (i=0; fstype[i]; i++) {
		rc = doPwMount(devicepath, mountpoint, fstype[i], 0, NULL);
		if (!rc)
			break;
	}
	if (!fstype[i])
		goto error;


	snprintf(markerpath, 128, "%s/%s", mountpoint, marker);
	if (!access(markerpath, F_OK)) {
		logMessage(INFO, "mountRocksDevice: found rocks device "
			"at %s, mounted on %s", 
			devicepath, mountpoint);
		return 0;
	}

error:
	unlink(devicepath);
	umount(mountpoint);
	return 1;
}
Beispiel #2
0
int doPwMount(char *dev, char *where, char *fs, char *options, char **err) {
    int rc, child, status, pipefd[2];
    char *opts = NULL, *device;

    if (mkdirChain(where))
        return IMOUNT_ERR_ERRNO;

    if (strstr(fs, "nfs")) {
        if (options) {
            if (asprintf(&opts, "%s,nolock", options) == -1) {
                fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__,
                        strerror(errno));
                fflush(stderr);
                abort();
            }
        } else {
            opts = strdup("nolock");
        }
        device = strdup(dev);
    } else {
        if ((options && strstr(options, "bind") == NULL) && 
            strncmp(dev, "LABEL=", 6) && strncmp(dev, "UUID=", 5) &&
            *dev != '/') {
           if (asprintf(&device, "/dev/%s", dev) == -1) {
               fprintf(stderr, "%s: %d: %s\n", __func__, __LINE__,
                       strerror(errno));
               fflush(stderr);
               abort();
           }
        } else {
           device = strdup(dev);
        }
        if (options)
            opts = strdup(options);
    }

    if (pipe(pipefd))
        return IMOUNT_ERR_ERRNO;

    if (!(child = fork())) {
        int fd;

        close(pipefd[0]);

        /* Close stdin entirely, redirect stdout to tty5, and redirect stderr
         * to a pipe so we can put error messages into exceptions.  We'll
         * only use these messages should mount also return an error code.
         */
        fd = open("/dev/tty5", O_RDONLY);
        close(STDIN_FILENO);
        dup2(fd, STDIN_FILENO);
        close(fd);

        fd = open("/dev/tty5", O_WRONLY);
        close(STDOUT_FILENO);
        dup2(fd, STDOUT_FILENO);

        dup2(pipefd[1], STDERR_FILENO);

        if (opts) {
            fprintf(stdout, "Running... /bin/mount -n -t %s -o %s %s %s\n",
                    fs, opts, device, where);
            rc = execl("/bin/mount",
                       "/bin/mount", "-n", "-t", fs, "-o", opts, device, where, NULL);
            exit(1);
        }
        else {
            fprintf(stdout, "Running... /bin/mount -n -t %s %s %s\n",
                    fs, device, where);
            rc = execl("/bin/mount", "/bin/mount", "-n", "-t", fs, device, where, NULL);
            exit(1);
        }
    }

    close(pipefd[1]);

    if (err != NULL)
        rc = readFD(pipefd[0], err);

    close(pipefd[0]);
    waitpid(child, &status, 0);

    free(opts);
    free(device);
    if (!WIFEXITED(status) || (WIFEXITED(status) && WEXITSTATUS(status)))
       return IMOUNT_ERR_OTHER;

    return 0;
}
Beispiel #3
0
/* this copies the contents of the driver disk to a ramdisk and loads
 * the moduleinfo, etc.  assumes a "valid" driver disk mounted at mntpt */
static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
    moduleDeps *modDepsPtr = loaderData->modDepsPtr;
    moduleInfoSet modInfo = loaderData->modInfo;
    char file[200], dest[200];
    char * title;
    struct moduleBallLocation * location;
    struct stat sb;
    static int disknum = 0;
    int version = 1;
    int fd, ret;

    /* check for both versions */
    sprintf(file, "%s/rhdd", mntpt);
    if (access(file, R_OK)) {
        version = 0;
        sprintf(file, "%s/rhdd-6.1", mntpt);
        if (access(file, R_OK)) {
            /* this can't happen, we already verified it! */
            return LOADER_BACK;
        } 
    }
    stat(file, &sb);
    title = malloc(sb.st_size + 1);

    fd = open(file, O_RDONLY);
    ret = read(fd, title, sb.st_size);
    if (title[sb.st_size - 1] == '\n')
        sb.st_size--;
    title[sb.st_size] = '\0';
    close(fd);

    sprintf(file, "/tmp/ramfs/DD-%d", disknum);
    mkdirChain(file);

    if (!FL_CMDLINE(flags)) {
        startNewt();
        winStatus(40, 3, _("Loading"), _("Reading driver disk..."));
    }

    sprintf(dest, "/tmp/ramfs/DD-%d", disknum);
    copyDirectory(mntpt, dest);

    location = malloc(sizeof(struct moduleBallLocation));
    location->title = strdup(title);
    location->path = sdupprintf("/tmp/ramfs/DD-%d/modules.cgz", disknum);
    location->version = version;

    char *fwdir = sdupprintf("/tmp/ramfs/DD-%d/firmware", disknum);
    if (!access(fwdir, R_OK|X_OK)) {
        add_fw_search_dir(loaderData, fwdir);
        stop_fw_loader(loaderData);
        start_fw_loader(loaderData);
    }
    free(fwdir);

    sprintf(file, "%s/modinfo", mntpt);
    readModuleInfo(file, modInfo, location, 1);

    sprintf(file, "%s/modules.dep", mntpt);
    mlLoadDeps(modDepsPtr, file);

    sprintf(file, "%s/modules.alias", mntpt);
    pciReadDrivers(file);

    if (!FL_CMDLINE(flags))
        newtPopWindow();

    disknum++;
    return 0;
}