From owner-svn-src-all@FreeBSD.ORG Thu Sep 1 19:39:10 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6D61B1065670; Thu, 1 Sep 2011 19:39:10 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5BB9D8FC0C; Thu, 1 Sep 2011 19:39:10 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p81JdAEl064776; Thu, 1 Sep 2011 19:39:10 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p81JdAfa064773; Thu, 1 Sep 2011 19:39:10 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201109011939.p81JdAfa064773@svn.freebsd.org> From: Dag-Erling Smorgrav Date: Thu, 1 Sep 2011 19:39:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225316 - stable/8/sbin/mdconfig X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Sep 2011 19:39:10 -0000 Author: des Date: Thu Sep 1 19:39:10 2011 New Revision: 225316 URL: http://svn.freebsd.org/changeset/base/225316 Log: MFH 221143, 221144: whitespace MFH 221232: make "-f" optional Modified: stable/8/sbin/mdconfig/mdconfig.8 stable/8/sbin/mdconfig/mdconfig.c Directory Properties: stable/8/sbin/mdconfig/ (props changed) Modified: stable/8/sbin/mdconfig/mdconfig.8 ============================================================================== --- stable/8/sbin/mdconfig/mdconfig.8 Thu Sep 1 16:47:49 2011 (r225315) +++ stable/8/sbin/mdconfig/mdconfig.8 Thu Sep 1 19:39:10 2011 (r225316) @@ -68,6 +68,8 @@ .Op Fl n .Op Fl v .Op Fl u Ar unit +.Nm +.Ar file .Sh DESCRIPTION The .Nm @@ -185,6 +187,15 @@ Request a specific unit number for the .Xr md 4 device instead of automatic allocation. .El +.Pp +The last form, +.Nm +.Ar file , +is provided for convenience as an abbreviation of +.Nm +.Fl a +.Fl t Ar vnode +.Fl f Ar file . .Sh EXAMPLES To create a 4 megabyte .Xr malloc 9 Modified: stable/8/sbin/mdconfig/mdconfig.c ============================================================================== --- stable/8/sbin/mdconfig/mdconfig.c Thu Sep 1 16:47:49 2011 (r225315) +++ stable/8/sbin/mdconfig/mdconfig.c Thu Sep 1 19:39:10 2011 (r225316) @@ -38,6 +38,7 @@ static enum {UNSET, ATTACH, DETACH, LIST static int nflag; static void usage(void); +static void md_set_file(const char *); static int md_find(char *, const char *); static int md_query(char *name); static int md_list(char *units, int opt); @@ -59,7 +60,8 @@ usage() " [-s size] [-S sectorsize] [-u unit]\n" " [-x sectors/track] [-y heads/cyl]\n" " mdconfig -d -u unit [-o [no]force]\n" -" mdconfig -l [-v] [-n] [-u unit]\n"); +" mdconfig -l [-v] [-n] [-u unit]\n" +" mdconfig file\n"); fprintf(stderr, "\t\ttype = {malloc, preload, vnode, swap}\n"); fprintf(stderr, "\t\toption = {cluster, compress, reserve}\n"); fprintf(stderr, "\t\tsize = %%d (512 byte blocks), %%db (B),\n"); @@ -82,10 +84,7 @@ main(int argc, char **argv) err(1, "could not allocate memory"); vflag = 0; bzero(mdio.md_file, PATH_MAX); - for (;;) { - ch = getopt(argc, argv, "ab:df:lno:s:S:t:u:vx:y:"); - if (ch == -1) - break; + while ((ch = getopt(argc, argv, "ab:df:lno:s:S:t:u:vx:y:")) != -1) { switch (ch) { case 'a': if (cmdline != 0) @@ -141,23 +140,9 @@ main(int argc, char **argv) mdio.md_options = MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS; cmdline = 2; } - if (cmdline != 2) - usage(); - if (realpath(optarg, mdio.md_file) == NULL) { - err(1, "could not find full path for %s", - optarg); - } - fd = open(mdio.md_file, O_RDONLY); - if (fd < 0) - err(1, "could not open %s", optarg); - else if (mdio.md_mediasize == 0) { - struct stat sb; - - if (fstat(fd, &sb) == -1) - err(1, "could not stat %s", optarg); - mdio.md_mediasize = sb.st_size; - } - close(fd); + if (cmdline != 2) + usage(); + md_set_file(optarg); break; case 'o': if (action == DETACH) { @@ -267,6 +252,19 @@ main(int argc, char **argv) usage(); } } + + argc -= optind; + argv += optind; + if (action == UNSET) { + if (argc != 1) + usage(); + action = ATTACH; + mdio.md_type = MD_VNODE; + mdio.md_options = MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS; + cmdline = 2; + md_set_file(*argv); + } + mdio.md_version = MDIOVERSION; if (!kld_isloaded("g_md") && kld_load("geom_md") == -1) @@ -294,7 +292,7 @@ main(int argc, char **argv) } if (action == LIST) { if (mdio.md_options & MD_AUTOUNIT) { - /* + /* * Listing all devices. This is why we pass NULL * together with OPT_LIST. */ @@ -322,6 +320,26 @@ main(int argc, char **argv) return (0); } +static void +md_set_file(const char *fn) +{ + struct stat sb; + int fd; + + if (realpath(fn, mdio.md_file) == NULL) + err(1, "could not find full path for %s", fn); + fd = open(mdio.md_file, O_RDONLY); + if (fd < 0) + err(1, "could not open %s", fn); + if (fstat(fd, &sb) == -1) + err(1, "could not stat %s", fn); + if (!S_ISREG(sb.st_mode)) + errx(1, "%s is not a regular file", fn); + if (mdio.md_mediasize == 0) + mdio.md_mediasize = sb.st_size; + close(fd); +} + /* * Lists md(4) disks. Is used also as a query routine, since it handles XML * interface. 'units' can be NULL for listing memory disks. It might be