dkscan_bsdlabel.c revision 1.1
11.1Smartin/* $NetBSD: dkscan_bsdlabel.c,v 1.1 2007/03/01 22:01:30 martin Exp $ */
21.1Smartin
31.1Smartin/*-
41.1Smartin * Copyright (c) 2007 The NetBSD Foundation, Inc.
51.1Smartin * All rights reserved.
61.1Smartin *
71.1Smartin * This code is derived from software contributed to The NetBSD Foundation
81.1Smartin * by Martin Husemann <martin@NetBSD.org>.
91.1Smartin *
101.1Smartin * Redistribution and use in source and binary forms, with or without
111.1Smartin * modification, are permitted provided that the following conditions
121.1Smartin * are met:
131.1Smartin * 1. Redistributions of source code must retain the above copyright
141.1Smartin *    notice, this list of conditions and the following disclaimer.
151.1Smartin * 2. Redistributions in binary form must reproduce the above copyright
161.1Smartin *    notice, this list of conditions and the following disclaimer in the
171.1Smartin *    documentation and/or other materials provided with the distribution.
181.1Smartin * 3. All advertising materials mentioning features or use of this software
191.1Smartin *    must display the following acknowledgement:
201.1Smartin *        This product includes software developed by the NetBSD
211.1Smartin *        Foundation, Inc. and its contributors.
221.1Smartin * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Smartin *    contributors may be used to endorse or promote products derived
241.1Smartin *    from this software without specific prior written permission.
251.1Smartin *
261.1Smartin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Smartin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Smartin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Smartin * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Smartin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Smartin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Smartin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Smartin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Smartin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Smartin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Smartin * POSSIBILITY OF SUCH DAMAGE.
371.1Smartin */
381.1Smartin
391.1Smartin#include <stdio.h>
401.1Smartin#include <stdlib.h>
411.1Smartin#include <stddef.h>
421.1Smartin#include <string.h>
431.1Smartin#include <unistd.h>
441.1Smartin#include <fcntl.h>
451.1Smartin#include <err.h>
461.1Smartin#include <util.h>
471.1Smartin#include <sys/disk.h>
481.1Smartin
491.1Smartin#include "dkscan_util.h"
501.1Smartin
511.1Smartin#include "dkwedge_bsdlabel.c"
521.1Smartin
531.1Smartinint
541.1Smartinmain(int argc, char **argv)
551.1Smartin{
561.1Smartin	struct disk d;
571.1Smartin	int ch;
581.1Smartin	char buf[PATH_MAX];
591.1Smartin	const char *devpart;
601.1Smartin
611.1Smartin	if (argc < 2)
621.1Smartin		usage();
631.1Smartin
641.1Smartin	while ((ch = getopt(argc, argv, "nv")) != -1) {
651.1Smartin		switch (ch) {
661.1Smartin		case 'n':
671.1Smartin			no_action = 1;
681.1Smartin			break;
691.1Smartin		case 'v':
701.1Smartin			verbose++;
711.1Smartin			break;
721.1Smartin		default:
731.1Smartin			usage();
741.1Smartin		}
751.1Smartin	}
761.1Smartin	if (optind >= argc)
771.1Smartin		usage();
781.1Smartin
791.1Smartin	disk_fd = opendisk(argv[optind], O_RDWR, buf, PATH_MAX, 0);
801.1Smartin	if (disk_fd == -1)
811.1Smartin		err(1, "%s", argv[optind]);
821.1Smartin
831.1Smartin	devpart = strrchr(argv[optind], '/');
841.1Smartin	if (devpart == NULL)
851.1Smartin		devpart = argv[optind];
861.1Smartin
871.1Smartin	memset(&d, 0, sizeof(d));
881.1Smartin	d.dk_name  = __UNCONST(devpart);
891.1Smartin	dkwedge_discover_bsdlabel(&d, NULL);
901.1Smartin
911.1Smartin	close(disk_fd);
921.1Smartin	return 0;
931.1Smartin}
941.1Smartin
951.1Smartinvoid
961.1Smartinusage(void)
971.1Smartin{
981.1Smartin	fprintf(stderr, "usage: %s [-vn] <diskname>\n"
991.1Smartin	    "  where\n"
1001.1Smartin	    "    -n don't change anything, just print info\n"
1011.1Smartin	    "    -v be more verbose\n"
1021.1Smartin	    "    <diskname> device to scan\n",
1031.1Smartin	    getprogname());
1041.1Smartin	exit(1);
1051.1Smartin}
106