static int ufs_fmount(mntfs *mf) { int error; error = mount_ufs(mf->mf_mount, mf->mf_info, mf->mf_mopts); if (error) { errno = error; plog(XLOG_ERROR, "mount_ufs: %m"); return error; } return 0; }
static char * getcmdlinefromroot(const char *cfgname) { const char *tryroot[] = { "/dev/ld0a", "/dev/sd0a", }; struct iso_args mntargs; struct stat sb; unsigned int i; int fd; char *p; if (mkdir("/rootfs", 0777) == -1) err(1, "mkdir /rootfs failed"); /* * XXX: should not be hardcoded to cd9660. but it is for now. * Maybe use mountroot() here somehow? */ for (i = 0; i < __arraycount(tryroot); i++) { memset(&mntargs, 0, sizeof(mntargs)); mntargs.fspec = tryroot[i]; if (mount(MOUNT_CD9660, "/rootfs", MNT_RDONLY, &mntargs, sizeof(mntargs)) == 0) { break; } } /* didn't find it that way. one more try: etfs for sda1 (EC2) */ if (i == __arraycount(tryroot)) { char *devpath; devpath = configetfs("sda1", 0); if (!devpath) errx(1, "failed to mount rootfs from image"); /* mount call will either succeed or panic */ mount_ufs("ext2fs", devpath, "/rootfs"); } /* * Ok, we've successfully mounted /rootfs. Now get the config. */ while (*cfgname == '/') cfgname++; if (chdir("/rootfs") == -1) err(1, "chdir rootfs"); if ((fd = open(cfgname, O_RDONLY)) == -1) err(1, "open %s", cfgname); if (stat(cfgname, &sb) == -1) err(1, "stat %s", cfgname); if (sb.st_size > CFGMAXSIZE) errx(1, "unbelievable cfg file size, increase CFGMAXSIZE"); if ((p = malloc(sb.st_size+1)) == NULL) err(1, "cfgname storage"); if (read(fd, p, sb.st_size) != sb.st_size) err(1, "read cfgfile"); close(fd); p[sb.st_size] = '\0'; return p; }
static int mountfs(const char *vfstype, const char *spec, const char *name, int flags, const char *options, const char *mntopts) { /* List of directories containing mount_xxx subcommands. */ static const char *edirs[] = { _PATH_SBIN, _PATH_USRSBIN, NULL }; const char *argv[100], **edir; struct statfs sf; pid_t pid; int argc, i, status; char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN]; #if __GNUC__ (void)&optbuf; (void)&name; #endif /* resolve the mountpoint with realpath(3) */ checkpath(name, mntpath); name = mntpath; if (mntopts == NULL) mntopts = ""; if (options == NULL) { if (*mntopts == '\0') { options = "rw"; } else { options = mntopts; mntopts = ""; } } optbuf = catopt(xstrdup(mntopts), options); if (strcmp(name, "/") == 0) flags |= MNT_UPDATE; if (flags & MNT_FORCE) optbuf = catopt(optbuf, "force"); if (flags & MNT_RDONLY) optbuf = catopt(optbuf, "ro"); /* * XXX * The mount_mfs (newfs) command uses -o to select the * optimization mode. We don't pass the default "-o rw" * for that reason. */ if (flags & MNT_UPDATE) optbuf = catopt(optbuf, "update"); argc = 0; argv[argc++] = vfstype; mangle(optbuf, &argc, argv); argv[argc++] = spec; argv[argc++] = name; argv[argc] = NULL; if (debug) { printf("exec: mount_%s", vfstype); for (i = 1; i < argc; i++) printf(" %s", argv[i]); printf("\n"); return (0); } switch (pid = fork()) { case -1: /* Error. */ warn("fork"); free(optbuf); return (1); case 0: /* Child. */ if (strcmp(vfstype, "ufs") == 0) exit(mount_ufs(argc, argv)); /* Go find an executable. */ for (edir = edirs; *edir; edir++) { snprintf(execname, sizeof(execname), "%s/mount_%s", *edir, vfstype); execv(execname, __DECONST(char * const *, argv)); } if (errno == ENOENT) { int len = 0; char *cp; for (edir = edirs; *edir; edir++) len += strlen(*edir) + 2; /* ", " */ if ((cp = malloc(len)) == NULL) errx(1, "malloc failed"); cp[0] = '\0'; for (edir = edirs; *edir; edir++) { strcat(cp, *edir); if (edir[1] != NULL) strcat(cp, ", "); } warn("exec mount_%s not found in %s", vfstype, cp); } exit(1); /* NOTREACHED */ default: /* Parent. */ free(optbuf); if (waitpid(pid, &status, 0) < 0) { warn("waitpid"); return (1); } if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) return (WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]); return (1); } if (verbose) { if (statfs(name, &sf) < 0) { warn("statfs %s", name); return (1); } if (fstab_style) putfsent(&sf); else prmount(&sf); } break; } return (0); }