dkscan_bsdlabel.c revision 1.3
11.3Sjoerg/* $NetBSD: dkscan_bsdlabel.c,v 1.3 2011/08/27 16:43:07 joerg 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 * 191.1Smartin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Smartin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Smartin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Smartin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Smartin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Smartin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Smartin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Smartin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Smartin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Smartin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Smartin * POSSIBILITY OF SUCH DAMAGE. 301.1Smartin */ 311.1Smartin 321.1Smartin#include <stdio.h> 331.1Smartin#include <stdlib.h> 341.1Smartin#include <stddef.h> 351.1Smartin#include <string.h> 361.1Smartin#include <unistd.h> 371.1Smartin#include <fcntl.h> 381.1Smartin#include <err.h> 391.1Smartin#include <util.h> 401.1Smartin#include <sys/disk.h> 411.1Smartin 421.1Smartin#include "dkscan_util.h" 431.1Smartin 441.1Smartin#include "dkwedge_bsdlabel.c" 451.1Smartin 461.3Sjoerg__dead static void usage(void); 471.3Sjoerg 481.1Smartinint 491.1Smartinmain(int argc, char **argv) 501.1Smartin{ 511.1Smartin struct disk d; 521.1Smartin int ch; 531.1Smartin char buf[PATH_MAX]; 541.1Smartin const char *devpart; 551.1Smartin 561.1Smartin if (argc < 2) 571.1Smartin usage(); 581.1Smartin 591.1Smartin while ((ch = getopt(argc, argv, "nv")) != -1) { 601.1Smartin switch (ch) { 611.1Smartin case 'n': 621.1Smartin no_action = 1; 631.1Smartin break; 641.1Smartin case 'v': 651.1Smartin verbose++; 661.1Smartin break; 671.1Smartin default: 681.1Smartin usage(); 691.1Smartin } 701.1Smartin } 711.1Smartin if (optind >= argc) 721.1Smartin usage(); 731.1Smartin 741.1Smartin disk_fd = opendisk(argv[optind], O_RDWR, buf, PATH_MAX, 0); 751.1Smartin if (disk_fd == -1) 761.1Smartin err(1, "%s", argv[optind]); 771.1Smartin 781.1Smartin devpart = strrchr(argv[optind], '/'); 791.1Smartin if (devpart == NULL) 801.1Smartin devpart = argv[optind]; 811.1Smartin 821.1Smartin memset(&d, 0, sizeof(d)); 831.1Smartin d.dk_name = __UNCONST(devpart); 841.1Smartin dkwedge_discover_bsdlabel(&d, NULL); 851.1Smartin 861.1Smartin close(disk_fd); 871.1Smartin return 0; 881.1Smartin} 891.1Smartin 901.1Smartinvoid 911.1Smartinusage(void) 921.1Smartin{ 931.1Smartin fprintf(stderr, "usage: %s [-vn] <diskname>\n" 941.1Smartin " where\n" 951.1Smartin " -n don't change anything, just print info\n" 961.1Smartin " -v be more verbose\n" 971.1Smartin " <diskname> device to scan\n", 981.1Smartin getprogname()); 991.1Smartin exit(1); 1001.1Smartin} 101