--- mount_md.c.org Tue Jul 25 00:33:59 2006 +++ mount_md.c Tue Jul 25 18:21:50 2006 @@ -75,6 +75,7 @@ static void do_mdconfig_attach(const char *, const enum md_types); static void do_mdconfig_attach_au(const char *, const enum md_types); static void do_mdconfig_detach(void); +static void do_fsck(const char *); static void do_mount(const char *, const char *); static void do_mtptsetup(const char *, struct mtpt_info *); static void do_newfs(const char *); @@ -87,10 +88,10 @@ { struct mtpt_info mi; /* Mountpoint info. */ char *mdconfig_arg, *newfs_arg, /* Args to helper programs. */ - *mount_arg; + *mount_arg, *fsck_arg; enum md_types mdtype; /* The type of our memory disk. */ bool have_mdtype; - bool detach, softdep, autounit, newfs; + bool detach, softdep, autounit, newfs, fsck; char *mtpoint, *unitstr; char *p; int ch; @@ -103,6 +104,7 @@ softdep = true; autounit = false; newfs = true; + fsck = false; have_mdtype = false; mdtype = MD_SWAP; mdname = MD_NAME; @@ -116,6 +118,7 @@ mdconfig_arg = strdup(""); newfs_arg = strdup(""); mount_arg = strdup(""); + fsck_arg = strdup(""); /* If we were started as mount_mfs or mfs, imply -C. */ if (strcmp(getprogname(), "mount_mfs") == 0 || @@ -123,7 +126,7 @@ compat = true; while ((ch = getopt(argc, argv, - "a:b:Cc:Dd:E:e:F:f:hi:LlMm:Nn:O:o:Pp:Ss:t:Uv:w:X")) != -1) + "a:b:Cc:Dd:E:e:F:f:hi:LlMm:Nn:O:o:Pp:Ss:T:t:Uv:w:X")) != -1) switch (ch) { case 'a': argappend(&newfs_arg, "-a %s", optarg); @@ -222,6 +225,23 @@ case 's': argappend(&mdconfig_arg, "-s %s", optarg); break; + case 'T': + if (compat) + usage(); + if (!fsck) { + fsck = true; + argappend(&fsck_arg, "-y"); + argappend(&fsck_arg, "-t %s", optarg); + } + break; + case 't': + if (compat) + usage(); + if (!fsck) { + fsck = true; + argappend(&fsck_arg, "-t %s", optarg); + } + break; case 'U': softdep = true; break; @@ -285,6 +305,8 @@ do_mdconfig_attach(mdconfig_arg, mdtype); if (newfs) do_newfs(newfs_arg); + if (fsck) + do_fsck(fsck_arg); do_mount(mount_arg, mtpoint); do_mtptsetup(mtpoint, &mi); @@ -436,6 +458,20 @@ if (rv && debug) /* This is allowed to fail. */ warnx("mdconfig (detach) exited with error code %d (ignored)", rv); +} + +/* + * run fsck on the configured (yet not mounted) memory disk. + */ +static void +do_fsck(const char *args) +{ + int rv; + + rv = run(NULL, "%s%s /dev/%s%d", "/sbin/fsck", args, + mdname, unit); + if (rv) + errx(1, "fsck exited with error code %d", rv); } /*