Home | History | Annotate | Line # | Download | only in raidctl
raidctl.c revision 1.26
      1  1.26      cgd /*      $NetBSD: raidctl.c,v 1.26 2001/02/19 22:56:22 cgd Exp $   */
      2  1.18  thorpej 
      3   1.1    oster /*-
      4   1.1    oster  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
      5   1.1    oster  * All rights reserved.
      6   1.1    oster  *
      7   1.1    oster  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1    oster  * by Greg Oster
      9   1.1    oster  *
     10   1.1    oster  * Redistribution and use in source and binary forms, with or without
     11   1.1    oster  * modification, are permitted provided that the following conditions
     12   1.1    oster  * are met:
     13   1.1    oster  * 1. Redistributions of source code must retain the above copyright
     14   1.1    oster  *    notice, this list of conditions and the following disclaimer.
     15   1.1    oster  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1    oster  *    notice, this list of conditions and the following disclaimer in the
     17   1.1    oster  *    documentation and/or other materials provided with the distribution.
     18   1.1    oster  * 3. All advertising materials mentioning features or use of this software
     19   1.1    oster  *    must display the following acknowledgement:
     20   1.1    oster  *        This product includes software developed by the NetBSD
     21   1.1    oster  *        Foundation, Inc. and its contributors.
     22   1.1    oster  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1    oster  *    contributors may be used to endorse or promote products derived
     24   1.1    oster  *    from this software without specific prior written permission.
     25   1.1    oster  *
     26   1.1    oster  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1    oster  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1    oster  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1    oster  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1    oster  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1    oster  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1    oster  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1    oster  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1    oster  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1    oster  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1    oster  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1    oster  */
     38   1.1    oster 
     39   1.1    oster /*
     40  1.18  thorpej  * This program is a re-write of the original rf_ctrl program
     41  1.18  thorpej  * distributed by CMU with RAIDframe 1.1.
     42  1.18  thorpej  *
     43  1.18  thorpej  * This program is the user-land interface to the RAIDframe kernel
     44  1.18  thorpej  * driver in NetBSD.
     45   1.1    oster  */
     46   1.1    oster 
     47   1.1    oster #include <sys/param.h>
     48   1.1    oster #include <sys/ioctl.h>
     49   1.1    oster #include <sys/stat.h>
     50  1.18  thorpej #include <sys/disklabel.h>
     51  1.18  thorpej 
     52   1.1    oster #include <ctype.h>
     53   1.1    oster #include <err.h>
     54   1.2   mjacob #include <errno.h>
     55  1.25    lukem #include <fcntl.h>
     56  1.25    lukem #include <stdio.h>
     57  1.25    lukem #include <stdlib.h>
     58   1.1    oster #include <string.h>
     59   1.3    oster #include <unistd.h>
     60  1.25    lukem #include <util.h>
     61   1.3    oster 
     62   1.1    oster #include "rf_raidframe.h"
     63   1.1    oster 
     64   1.1    oster int     main __P((int, char *[]));
     65  1.18  thorpej void	do_ioctl __P((int, u_long, void *, const char *));
     66   1.5    oster static  void rf_configure __P((int, char*, int));
     67  1.18  thorpej static  const char *device_status __P((RF_DiskStatus_t));
     68   1.1    oster static  void rf_get_device_status __P((int));
     69   1.6    oster static  void get_component_number __P((int, char *, int *, int *));
     70   1.1    oster static  void rf_fail_disk __P((int, char *, int));
     71   1.1    oster static  void usage __P((void));
     72   1.5    oster static  void get_component_label __P((int, char *));
     73   1.5    oster static  void set_component_label __P((int, char *));
     74   1.5    oster static  void init_component_labels __P((int, int));
     75  1.12    oster static  void set_autoconfig __P((int, int, char *));
     76   1.5    oster static  void add_hot_spare __P((int, char *));
     77   1.6    oster static  void remove_hot_spare __P((int, char *));
     78   1.6    oster static  void rebuild_in_place __P((int, char *));
     79  1.14    oster static  void check_status __P((int,int));
     80  1.18  thorpej static  void check_parity __P((int,int, char *));
     81  1.17  thorpej static  void do_meter __P((int, u_long));
     82  1.10    oster static  void get_bar __P((char *, double, int));
     83  1.10    oster static  void get_time_string __P((char *, int));
     84  1.10    oster 
     85  1.18  thorpej int verbose;
     86   1.1    oster 
     87   1.1    oster int
     88   1.1    oster main(argc,argv)
     89   1.1    oster 	int argc;
     90   1.1    oster 	char *argv[];
     91   1.1    oster {
     92   1.1    oster 	int ch;
     93   1.1    oster 	int num_options;
     94   1.1    oster 	unsigned long action;
     95   1.1    oster 	char config_filename[PATH_MAX];
     96   1.1    oster 	char dev_name[PATH_MAX];
     97   1.1    oster 	char name[PATH_MAX];
     98   1.5    oster 	char component[PATH_MAX];
     99  1.12    oster 	char autoconf[10];
    100   1.1    oster 	int do_recon;
    101   1.7    oster 	int do_rewrite;
    102   1.7    oster 	int is_clean;
    103   1.1    oster 	int raidID;
    104   1.5    oster 	int serial_number;
    105   1.1    oster 	struct stat st;
    106   1.1    oster 	int fd;
    107   1.5    oster 	int force;
    108   1.1    oster 
    109   1.1    oster 	num_options = 0;
    110   1.1    oster 	action = 0;
    111   1.1    oster 	do_recon = 0;
    112   1.7    oster 	do_rewrite = 0;
    113   1.7    oster 	is_clean = 0;
    114   1.5    oster 	force = 0;
    115   1.1    oster 
    116  1.12    oster 	while ((ch = getopt(argc, argv, "a:A:Bc:C:f:F:g:iI:l:r:R:sSpPuv"))
    117  1.12    oster 	       != -1)
    118   1.1    oster 		switch(ch) {
    119   1.5    oster 		case 'a':
    120   1.5    oster 			action = RAIDFRAME_ADD_HOT_SPARE;
    121   1.5    oster 			strncpy(component, optarg, PATH_MAX);
    122   1.5    oster 			num_options++;
    123   1.5    oster 			break;
    124  1.12    oster 		case 'A':
    125  1.12    oster 			action = RAIDFRAME_SET_AUTOCONFIG;
    126  1.12    oster 			strncpy(autoconf, optarg, 10);
    127  1.12    oster 			num_options++;
    128  1.12    oster 			break;
    129   1.6    oster 		case 'B':
    130   1.6    oster 			action = RAIDFRAME_COPYBACK;
    131   1.6    oster 			num_options++;
    132   1.6    oster 			break;
    133   1.1    oster 		case 'c':
    134   1.6    oster 			action = RAIDFRAME_CONFIGURE;
    135   1.1    oster 			strncpy(config_filename,optarg,PATH_MAX);
    136   1.6    oster 			force = 0;
    137   1.1    oster 			num_options++;
    138   1.1    oster 			break;
    139   1.1    oster 		case 'C':
    140   1.6    oster 			strncpy(config_filename,optarg,PATH_MAX);
    141   1.6    oster 			action = RAIDFRAME_CONFIGURE;
    142   1.6    oster 			force = 1;
    143   1.1    oster 			num_options++;
    144   1.1    oster 			break;
    145   1.1    oster 		case 'f':
    146   1.1    oster 			action = RAIDFRAME_FAIL_DISK;
    147   1.6    oster 			strncpy(component, optarg, PATH_MAX);
    148   1.1    oster 			do_recon = 0;
    149   1.1    oster 			num_options++;
    150   1.1    oster 			break;
    151   1.1    oster 		case 'F':
    152   1.1    oster 			action = RAIDFRAME_FAIL_DISK;
    153   1.6    oster 			strncpy(component, optarg, PATH_MAX);
    154   1.1    oster 			do_recon = 1;
    155   1.5    oster 			num_options++;
    156   1.5    oster 			break;
    157   1.5    oster 		case 'g':
    158   1.5    oster 			action = RAIDFRAME_GET_COMPONENT_LABEL;
    159   1.5    oster 			strncpy(component, optarg, PATH_MAX);
    160   1.5    oster 			num_options++;
    161   1.5    oster 			break;
    162   1.6    oster 		case 'i':
    163   1.6    oster 			action = RAIDFRAME_REWRITEPARITY;
    164   1.6    oster 			num_options++;
    165   1.6    oster 			break;
    166   1.5    oster 		case 'I':
    167   1.5    oster 			action = RAIDFRAME_INIT_LABELS;
    168   1.5    oster 			serial_number = atoi(optarg);
    169   1.5    oster 			num_options++;
    170   1.5    oster 			break;
    171   1.6    oster 		case 'l':
    172   1.5    oster 			action = RAIDFRAME_SET_COMPONENT_LABEL;
    173   1.5    oster 			strncpy(component, optarg, PATH_MAX);
    174   1.1    oster 			num_options++;
    175   1.1    oster 			break;
    176   1.1    oster 		case 'r':
    177   1.6    oster 			action = RAIDFRAME_REMOVE_HOT_SPARE;
    178   1.6    oster 			strncpy(component, optarg, PATH_MAX);
    179   1.1    oster 			num_options++;
    180   1.1    oster 			break;
    181   1.1    oster 		case 'R':
    182   1.6    oster 			strncpy(component,optarg,PATH_MAX);
    183   1.6    oster 			action = RAIDFRAME_REBUILD_IN_PLACE;
    184   1.1    oster 			num_options++;
    185   1.1    oster 			break;
    186   1.1    oster 		case 's':
    187   1.1    oster 			action = RAIDFRAME_GET_INFO;
    188   1.1    oster 			num_options++;
    189   1.1    oster 			break;
    190   1.6    oster 		case 'S':
    191  1.19    oster 			action = RAIDFRAME_CHECK_RECON_STATUS_EXT;
    192   1.6    oster 			num_options++;
    193   1.6    oster 			break;
    194   1.7    oster 		case 'p':
    195   1.7    oster 			action = RAIDFRAME_CHECK_PARITY;
    196   1.7    oster 			num_options++;
    197   1.7    oster 			break;
    198   1.7    oster 		case 'P':
    199   1.7    oster 			action = RAIDFRAME_CHECK_PARITY;
    200   1.7    oster 			do_rewrite = 1;
    201   1.7    oster 			num_options++;
    202   1.7    oster 			break;
    203   1.1    oster 		case 'u':
    204   1.1    oster 			action = RAIDFRAME_SHUTDOWN;
    205   1.1    oster 			num_options++;
    206   1.1    oster 			break;
    207  1.10    oster 		case 'v':
    208  1.10    oster 			verbose = 1;
    209  1.10    oster 			/* Don't bump num_options, as '-v' is not
    210  1.10    oster 			   an option like the others */
    211  1.10    oster 			/* num_options++; */
    212  1.10    oster 			break;
    213   1.1    oster 		default:
    214   1.1    oster 			usage();
    215   1.1    oster 		}
    216   1.1    oster 	argc -= optind;
    217   1.1    oster 	argv += optind;
    218   1.1    oster 
    219   1.1    oster 	if ((num_options > 1) || (argc == NULL))
    220   1.1    oster 		usage();
    221   1.1    oster 
    222   1.1    oster 	strncpy(name,argv[0],PATH_MAX);
    223  1.25    lukem 	fd = opendisk(name, O_RDWR, dev_name, sizeof(dev_name), 1);
    224  1.25    lukem 	if (fd == -1) {
    225  1.25    lukem 		fprintf(stderr, "%s: unable to open device file: %s\n",
    226  1.26      cgd 			getprogname(), name);
    227  1.25    lukem 		exit(1);
    228  1.25    lukem 	}
    229  1.25    lukem 	if (fstat(fd, &st) != 0) {
    230   1.1    oster 		fprintf(stderr,"%s: stat failure on: %s\n",
    231  1.26      cgd 			getprogname(), dev_name);
    232  1.25    lukem 		exit(1);
    233   1.1    oster 	}
    234   1.1    oster 	if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) {
    235   1.1    oster 		fprintf(stderr,"%s: invalid device: %s\n",
    236  1.26      cgd 			getprogname(), dev_name);
    237  1.25    lukem 		exit(1);
    238   1.1    oster 	}
    239   1.1    oster 
    240   1.1    oster 	raidID = RF_DEV2RAIDID(st.st_rdev);
    241   1.1    oster 
    242   1.1    oster 	switch(action) {
    243   1.5    oster 	case RAIDFRAME_ADD_HOT_SPARE:
    244  1.12    oster 		add_hot_spare(fd, component);
    245   1.5    oster 		break;
    246   1.6    oster 	case RAIDFRAME_REMOVE_HOT_SPARE:
    247  1.12    oster 		remove_hot_spare(fd, component);
    248   1.6    oster 		break;
    249   1.1    oster 	case RAIDFRAME_CONFIGURE:
    250  1.12    oster 		rf_configure(fd, config_filename, force);
    251  1.12    oster 		break;
    252  1.12    oster 	case RAIDFRAME_SET_AUTOCONFIG:
    253  1.12    oster 		set_autoconfig(fd, raidID, autoconf);
    254   1.1    oster 		break;
    255   1.1    oster 	case RAIDFRAME_COPYBACK:
    256   1.1    oster 		printf("Copyback.\n");
    257   1.1    oster 		do_ioctl(fd, RAIDFRAME_COPYBACK, NULL, "RAIDFRAME_COPYBACK");
    258  1.10    oster 		if (verbose) {
    259  1.10    oster 			sleep(3); /* XXX give the copyback a chance to start */
    260  1.10    oster 			printf("Copyback status:\n");
    261  1.19    oster 			do_meter(fd,RAIDFRAME_CHECK_COPYBACK_STATUS_EXT);
    262  1.10    oster 		}
    263   1.1    oster 		break;
    264   1.1    oster 	case RAIDFRAME_FAIL_DISK:
    265  1.12    oster 		rf_fail_disk(fd, component, do_recon);
    266   1.5    oster 		break;
    267   1.5    oster 	case RAIDFRAME_SET_COMPONENT_LABEL:
    268  1.12    oster 		set_component_label(fd, component);
    269   1.5    oster 		break;
    270   1.5    oster 	case RAIDFRAME_GET_COMPONENT_LABEL:
    271  1.12    oster 		get_component_label(fd, component);
    272   1.5    oster 		break;
    273   1.5    oster 	case RAIDFRAME_INIT_LABELS:
    274  1.12    oster 		init_component_labels(fd, serial_number);
    275   1.1    oster 		break;
    276   1.1    oster 	case RAIDFRAME_REWRITEPARITY:
    277   1.1    oster 		printf("Initiating re-write of parity\n");
    278   1.1    oster 		do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL,
    279   1.1    oster 			 "RAIDFRAME_REWRITEPARITY");
    280  1.10    oster 		if (verbose) {
    281  1.10    oster 			sleep(3); /* XXX give it time to get started */
    282  1.10    oster 			printf("Parity Re-write status:\n");
    283  1.19    oster 			do_meter(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT);
    284  1.10    oster 		}
    285   1.1    oster 		break;
    286  1.19    oster 	case RAIDFRAME_CHECK_RECON_STATUS_EXT:
    287  1.14    oster 		check_status(fd,1);
    288   1.1    oster 		break;
    289   1.1    oster 	case RAIDFRAME_GET_INFO:
    290   1.1    oster 		rf_get_device_status(fd);
    291   1.1    oster 		break;
    292   1.6    oster 	case RAIDFRAME_REBUILD_IN_PLACE:
    293  1.12    oster 		rebuild_in_place(fd, component);
    294   1.6    oster 		break;
    295   1.7    oster 	case RAIDFRAME_CHECK_PARITY:
    296  1.12    oster 		check_parity(fd, do_rewrite, dev_name);
    297   1.7    oster 		break;
    298   1.1    oster 	case RAIDFRAME_SHUTDOWN:
    299   1.1    oster 		do_ioctl(fd, RAIDFRAME_SHUTDOWN, NULL, "RAIDFRAME_SHUTDOWN");
    300   1.1    oster 		break;
    301   1.1    oster 	default:
    302   1.1    oster 		break;
    303   1.1    oster 	}
    304   1.1    oster 
    305   1.1    oster 	close(fd);
    306   1.1    oster 	exit(0);
    307   1.1    oster }
    308   1.1    oster 
    309  1.10    oster void
    310   1.1    oster do_ioctl(fd, command, arg, ioctl_name)
    311   1.1    oster 	int fd;
    312   1.1    oster 	unsigned long command;
    313   1.1    oster 	void *arg;
    314  1.17  thorpej 	const char *ioctl_name;
    315   1.1    oster {
    316   1.1    oster 	if (ioctl(fd, command, arg) < 0) {
    317   1.1    oster 		warn("ioctl (%s) failed", ioctl_name);
    318   1.1    oster 		exit(1);
    319   1.1    oster 	}
    320   1.1    oster }
    321   1.1    oster 
    322   1.1    oster 
    323   1.1    oster static void
    324   1.5    oster rf_configure(fd,config_file,force)
    325   1.1    oster 	int fd;
    326   1.1    oster 	char *config_file;
    327   1.5    oster 	int force;
    328   1.1    oster {
    329   1.1    oster 	void *generic;
    330   1.1    oster 	RF_Config_t cfg;
    331   1.1    oster 
    332   1.9    oster 	if (rf_MakeConfig( config_file, &cfg ) != 0) {
    333   1.1    oster 		fprintf(stderr,"%s: unable to create RAIDframe %s\n",
    334  1.26      cgd 			getprogname(), "configuration structure\n");
    335   1.1    oster 		exit(1);
    336   1.1    oster 	}
    337   1.1    oster 
    338   1.6    oster 	cfg.force = force;
    339   1.6    oster 
    340   1.1    oster 	/*
    341  1.18  thorpej 	 * Note the extra level of redirection needed here, since
    342  1.18  thorpej 	 * what we really want to pass in is a pointer to the pointer to
    343  1.18  thorpej 	 * the configuration structure.
    344   1.1    oster 	 */
    345   1.1    oster 
    346   1.1    oster 	generic = (void *) &cfg;
    347   1.6    oster 	do_ioctl(fd, RAIDFRAME_CONFIGURE, &generic, "RAIDFRAME_CONFIGURE");
    348   1.1    oster }
    349   1.1    oster 
    350  1.18  thorpej static const char *
    351   1.1    oster device_status(status)
    352   1.1    oster 	RF_DiskStatus_t status;
    353   1.1    oster {
    354   1.1    oster 
    355   1.1    oster 	switch (status) {
    356   1.1    oster 	case rf_ds_optimal:
    357  1.18  thorpej 		return ("optimal");
    358   1.1    oster 		break;
    359   1.1    oster 	case rf_ds_failed:
    360  1.18  thorpej 		return ("failed");
    361   1.1    oster 		break;
    362   1.1    oster 	case rf_ds_reconstructing:
    363  1.18  thorpej 		return ("reconstructing");
    364   1.1    oster 		break;
    365   1.1    oster 	case rf_ds_dist_spared:
    366  1.18  thorpej 		return ("dist_spared");
    367   1.1    oster 		break;
    368   1.1    oster 	case rf_ds_spared:
    369  1.18  thorpej 		return ("spared");
    370   1.1    oster 		break;
    371   1.1    oster 	case rf_ds_spare:
    372  1.18  thorpej 		return ("spare");
    373   1.1    oster 		break;
    374   1.1    oster 	case rf_ds_used_spare:
    375  1.18  thorpej 		return ("used_spare");
    376   1.1    oster 		break;
    377   1.1    oster 	default:
    378  1.18  thorpej 		return ("UNKNOWN");
    379   1.1    oster 	}
    380  1.18  thorpej 	/* NOTREACHED */
    381   1.1    oster }
    382   1.1    oster 
    383   1.1    oster static void
    384   1.1    oster rf_get_device_status(fd)
    385   1.1    oster 	int fd;
    386   1.1    oster {
    387   1.1    oster 	RF_DeviceConfig_t device_config;
    388   1.1    oster 	void *cfg_ptr;
    389   1.8    oster 	int is_clean;
    390   1.1    oster 	int i;
    391   1.1    oster 
    392   1.1    oster 	cfg_ptr = &device_config;
    393   1.1    oster 
    394   1.1    oster 	do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr, "RAIDFRAME_GET_INFO");
    395   1.1    oster 
    396   1.1    oster 	printf("Components:\n");
    397   1.1    oster 	for(i=0; i < device_config.ndevs; i++) {
    398   1.1    oster 		printf("%20s: %s\n", device_config.devs[i].devname,
    399   1.1    oster 		       device_status(device_config.devs[i].status));
    400   1.1    oster 	}
    401   1.1    oster 	if (device_config.nspares > 0) {
    402   1.1    oster 		printf("Spares:\n");
    403   1.1    oster 		for(i=0; i < device_config.nspares; i++) {
    404   1.5    oster 			printf("%20s: %s\n",
    405   1.1    oster 			       device_config.spares[i].devname,
    406   1.1    oster 			       device_status(device_config.spares[i].status));
    407   1.1    oster 		}
    408   1.1    oster 	} else {
    409   1.1    oster 		printf("No spares.\n");
    410   1.8    oster 	}
    411  1.14    oster 	for(i=0; i < device_config.ndevs; i++) {
    412  1.14    oster 		if (device_config.devs[i].status == rf_ds_optimal) {
    413  1.14    oster 			get_component_label(fd, device_config.devs[i].devname);
    414  1.14    oster 		} else {
    415  1.14    oster 			printf("%s status is: %s.  Skipping label.\n",
    416  1.14    oster 			       device_config.devs[i].devname,
    417  1.14    oster 			       device_status(device_config.devs[i].status));
    418  1.14    oster 		}
    419  1.14    oster 	}
    420  1.23    oster 
    421  1.21    oster 	if (device_config.nspares > 0) {
    422  1.21    oster 		for(i=0; i < device_config.nspares; i++) {
    423  1.21    oster 			if ((device_config.spares[i].status ==
    424  1.21    oster 			     rf_ds_optimal) ||
    425  1.21    oster 			    (device_config.spares[i].status ==
    426  1.21    oster 			     rf_ds_used_spare)) {
    427  1.21    oster 				get_component_label(fd,
    428  1.21    oster 					    device_config.spares[i].devname);
    429  1.21    oster 			} else {
    430  1.21    oster 				printf("%s status is: %s.  Skipping label.\n",
    431  1.21    oster 				       device_config.spares[i].devname,
    432  1.21    oster 				       device_status(device_config.spares[i].status));
    433  1.21    oster 			}
    434  1.21    oster 		}
    435  1.21    oster 	}
    436  1.23    oster 
    437   1.8    oster 	do_ioctl(fd, RAIDFRAME_CHECK_PARITY, &is_clean,
    438   1.8    oster 		 "RAIDFRAME_CHECK_PARITY");
    439   1.8    oster 	if (is_clean) {
    440   1.8    oster 		printf("Parity status: clean\n");
    441   1.8    oster 	} else {
    442   1.8    oster 		printf("Parity status: DIRTY\n");
    443   1.1    oster 	}
    444  1.14    oster 	check_status(fd,0);
    445   1.1    oster }
    446   1.1    oster 
    447   1.1    oster static void
    448   1.6    oster get_component_number(fd, component_name, component_number, num_columns)
    449   1.1    oster 	int fd;
    450   1.6    oster 	char *component_name;
    451   1.6    oster 	int *component_number;
    452   1.6    oster 	int *num_columns;
    453   1.1    oster {
    454   1.1    oster 	RF_DeviceConfig_t device_config;
    455   1.1    oster 	void *cfg_ptr;
    456   1.1    oster 	int i;
    457   1.1    oster 	int found;
    458   1.1    oster 
    459   1.6    oster 	*component_number = -1;
    460   1.1    oster 
    461   1.1    oster 	/* Assuming a full path spec... */
    462   1.1    oster 	cfg_ptr = &device_config;
    463   1.1    oster 	do_ioctl(fd, RAIDFRAME_GET_INFO, &cfg_ptr,
    464   1.1    oster 		 "RAIDFRAME_GET_INFO");
    465   1.6    oster 
    466   1.6    oster 	*num_columns = device_config.cols;
    467   1.6    oster 
    468   1.1    oster 	found = 0;
    469   1.1    oster 	for(i=0; i < device_config.ndevs; i++) {
    470   1.6    oster 		if (strncmp(component_name, device_config.devs[i].devname,
    471   1.1    oster 			    PATH_MAX)==0) {
    472   1.1    oster 			found = 1;
    473   1.6    oster 			*component_number = i;
    474   1.1    oster 		}
    475   1.1    oster 	}
    476  1.21    oster 	if (!found) { /* maybe it's a spare? */
    477  1.21    oster 		for(i=0; i < device_config.nspares; i++) {
    478  1.21    oster 			if (strncmp(component_name,
    479  1.21    oster 				    device_config.spares[i].devname,
    480  1.21    oster 				    PATH_MAX)==0) {
    481  1.21    oster 				found = 1;
    482  1.21    oster 				*component_number = i + device_config.ndevs;
    483  1.23    oster 				/* the way spares are done should
    484  1.23    oster 				   really change... */
    485  1.23    oster 				*num_columns = device_config.cols +
    486  1.23    oster 					device_config.nspares;
    487  1.21    oster 			}
    488  1.21    oster 		}
    489  1.21    oster 	}
    490  1.21    oster 
    491   1.1    oster 	if (!found) {
    492  1.26      cgd 		fprintf(stderr,"%s: %s is not a component %s", getprogname(),
    493   1.6    oster 			component_name, "of this device\n");
    494   1.1    oster 		exit(1);
    495   1.1    oster 	}
    496   1.6    oster }
    497   1.6    oster 
    498   1.6    oster static void
    499   1.6    oster rf_fail_disk(fd, component_to_fail, do_recon)
    500   1.6    oster 	int fd;
    501   1.6    oster 	char *component_to_fail;
    502   1.6    oster 	int do_recon;
    503   1.6    oster {
    504   1.6    oster 	struct rf_recon_req recon_request;
    505   1.6    oster 	int component_num;
    506   1.6    oster 	int num_cols;
    507   1.6    oster 
    508   1.6    oster 	get_component_number(fd, component_to_fail, &component_num, &num_cols);
    509   1.1    oster 
    510   1.6    oster 	recon_request.row = component_num / num_cols;
    511   1.6    oster 	recon_request.col = component_num % num_cols;
    512   1.1    oster 	if (do_recon) {
    513   1.1    oster 		recon_request.flags = RF_FDFLAGS_RECON;
    514   1.1    oster 	} else {
    515   1.1    oster 		recon_request.flags = RF_FDFLAGS_NONE;
    516   1.1    oster 	}
    517   1.1    oster 	do_ioctl(fd, RAIDFRAME_FAIL_DISK, &recon_request,
    518   1.1    oster 		 "RAIDFRAME_FAIL_DISK");
    519  1.10    oster 	if (do_recon && verbose) {
    520  1.10    oster 		printf("Reconstruction status:\n");
    521  1.10    oster 		sleep(3); /* XXX give reconstruction a chance to start */
    522  1.19    oster 		do_meter(fd,RAIDFRAME_CHECK_RECON_STATUS_EXT);
    523  1.10    oster 	}
    524   1.1    oster }
    525   1.1    oster 
    526   1.1    oster static void
    527   1.5    oster get_component_label(fd, component)
    528   1.5    oster 	int fd;
    529   1.5    oster 	char *component;
    530   1.5    oster {
    531   1.5    oster 	RF_ComponentLabel_t component_label;
    532   1.5    oster 	void *label_ptr;
    533   1.5    oster 	int component_num;
    534   1.6    oster 	int num_cols;
    535   1.5    oster 
    536   1.6    oster 	get_component_number(fd, component, &component_num, &num_cols);
    537   1.5    oster 
    538   1.5    oster 	memset( &component_label, 0, sizeof(RF_ComponentLabel_t));
    539   1.6    oster 	component_label.row = component_num / num_cols;
    540   1.6    oster 	component_label.column = component_num % num_cols;
    541   1.5    oster 
    542   1.5    oster 	label_ptr = &component_label;
    543   1.5    oster 	do_ioctl( fd, RAIDFRAME_GET_COMPONENT_LABEL, &label_ptr,
    544   1.5    oster 		  "RAIDFRAME_GET_COMPONENT_LABEL");
    545   1.5    oster 
    546   1.5    oster 	printf("Component label for %s:\n",component);
    547  1.12    oster 
    548  1.25    lukem 	printf("   Row: %d, Column: %d, Num Rows: %d, Num Columns: %d\n",
    549  1.12    oster 	       component_label.row, component_label.column,
    550  1.12    oster 	       component_label.num_rows, component_label.num_columns);
    551  1.25    lukem 	printf("   Version: %d, Serial Number: %d, Mod Counter: %d\n",
    552  1.12    oster 	       component_label.version, component_label.serial_number,
    553  1.12    oster 	       component_label.mod_counter);
    554  1.25    lukem 	printf("   Clean: %s, Status: %d\n",
    555  1.12    oster 	       component_label.clean ? "Yes" : "No",
    556  1.12    oster 	       component_label.status );
    557  1.25    lukem 	printf("   sectPerSU: %d, SUsPerPU: %d, SUsPerRU: %d\n",
    558  1.12    oster 	       component_label.sectPerSU, component_label.SUsPerPU,
    559  1.12    oster 	       component_label.SUsPerRU);
    560  1.25    lukem 	printf("   Queue size: %d, blocksize: %d, numBlocks: %d\n",
    561  1.25    lukem 	       component_label.maxOutstanding, component_label.blockSize,
    562  1.25    lukem 	       component_label.numBlocks);
    563  1.25    lukem 	printf("   RAID Level: %c\n", (char) component_label.parityConfig);
    564  1.12    oster 	printf("   Autoconfig: %s\n",
    565  1.12    oster 	       component_label.autoconfigure ? "Yes" : "No" );
    566  1.15    oster 	printf("   Root partition: %s\n",
    567  1.15    oster 	       component_label.root_partition ? "Yes" : "No" );
    568  1.12    oster 	printf("   Last configured as: raid%d\n", component_label.last_unit );
    569   1.5    oster }
    570   1.5    oster 
    571   1.5    oster static void
    572   1.5    oster set_component_label(fd, component)
    573   1.5    oster 	int fd;
    574   1.5    oster 	char *component;
    575   1.5    oster {
    576   1.5    oster 	RF_ComponentLabel_t component_label;
    577   1.5    oster 	int component_num;
    578   1.6    oster 	int num_cols;
    579   1.5    oster 
    580   1.6    oster 	get_component_number(fd, component, &component_num, &num_cols);
    581   1.6    oster 
    582   1.6    oster 	/* XXX This is currently here for testing, and future expandability */
    583   1.5    oster 
    584   1.5    oster 	component_label.version = 1;
    585   1.5    oster 	component_label.serial_number = 123456;
    586   1.5    oster 	component_label.mod_counter = 0;
    587   1.6    oster 	component_label.row = component_num / num_cols;
    588   1.6    oster 	component_label.column = component_num % num_cols;
    589   1.5    oster 	component_label.num_rows = 0;
    590   1.5    oster 	component_label.num_columns = 5;
    591   1.5    oster 	component_label.clean = 0;
    592   1.5    oster 	component_label.status = 1;
    593   1.5    oster 
    594   1.5    oster 	do_ioctl( fd, RAIDFRAME_SET_COMPONENT_LABEL, &component_label,
    595   1.5    oster 		  "RAIDFRAME_SET_COMPONENT_LABEL");
    596   1.5    oster }
    597   1.5    oster 
    598   1.5    oster 
    599   1.5    oster static void
    600   1.5    oster init_component_labels(fd, serial_number)
    601   1.5    oster 	int fd;
    602   1.5    oster 	int serial_number;
    603   1.5    oster {
    604   1.5    oster 	RF_ComponentLabel_t component_label;
    605   1.5    oster 
    606   1.5    oster 	component_label.version = 0;
    607   1.5    oster 	component_label.serial_number = serial_number;
    608   1.5    oster 	component_label.mod_counter = 0;
    609   1.5    oster 	component_label.row = 0;
    610   1.5    oster 	component_label.column = 0;
    611   1.5    oster 	component_label.num_rows = 0;
    612   1.5    oster 	component_label.num_columns = 0;
    613   1.5    oster 	component_label.clean = 0;
    614   1.5    oster 	component_label.status = 0;
    615   1.5    oster 
    616   1.5    oster 	do_ioctl( fd, RAIDFRAME_INIT_LABELS, &component_label,
    617   1.5    oster 		  "RAIDFRAME_SET_COMPONENT_LABEL");
    618  1.12    oster }
    619  1.12    oster 
    620  1.12    oster static void
    621  1.12    oster set_autoconfig(fd, raidID, autoconf)
    622  1.12    oster 	int fd;
    623  1.12    oster 	int raidID;
    624  1.12    oster 	char *autoconf;
    625  1.12    oster {
    626  1.12    oster 	int auto_config;
    627  1.12    oster 	int root_config;
    628  1.12    oster 
    629  1.12    oster 	auto_config = 0;
    630  1.12    oster 	root_config = 0;
    631  1.12    oster 
    632  1.12    oster 	if (strncasecmp(autoconf,"root", 4) == 0) {
    633  1.12    oster 		root_config = 1;
    634  1.12    oster 	}
    635  1.12    oster 
    636  1.12    oster 	if ((strncasecmp(autoconf,"yes", 3) == 0) ||
    637  1.12    oster 	    root_config == 1) {
    638  1.12    oster 		auto_config = 1;
    639  1.12    oster 	}
    640  1.12    oster 
    641  1.12    oster 	do_ioctl(fd, RAIDFRAME_SET_AUTOCONFIG, &auto_config,
    642  1.12    oster 		 "RAIDFRAME_SET_AUTOCONFIG");
    643  1.12    oster 
    644  1.12    oster 	do_ioctl(fd, RAIDFRAME_SET_ROOT, &root_config,
    645  1.12    oster 		 "RAIDFRAME_SET_ROOT");
    646  1.12    oster 
    647  1.12    oster 	printf("raid%d: Autoconfigure: %s\n", raidID,
    648  1.12    oster 	       auto_config ? "Yes" : "No");
    649  1.12    oster 
    650  1.12    oster 	if (root_config == 1) {
    651  1.12    oster 		printf("raid%d: Root: %s\n", raidID,
    652  1.12    oster 		       auto_config ? "Yes" : "No");
    653  1.12    oster 	}
    654   1.5    oster }
    655   1.5    oster 
    656   1.5    oster static void
    657   1.5    oster add_hot_spare(fd, component)
    658   1.5    oster 	int fd;
    659   1.5    oster 	char *component;
    660   1.5    oster {
    661   1.6    oster 	RF_SingleComponent_t hot_spare;
    662   1.5    oster 
    663   1.6    oster 	hot_spare.row = 0;
    664   1.6    oster 	hot_spare.column = 0;
    665   1.6    oster 	strncpy(hot_spare.component_name, component,
    666   1.6    oster 		sizeof(hot_spare.component_name));
    667   1.5    oster 
    668   1.5    oster 	do_ioctl( fd, RAIDFRAME_ADD_HOT_SPARE, &hot_spare,
    669   1.5    oster 		  "RAIDFRAME_ADD_HOT_SPARE");
    670   1.6    oster }
    671   1.6    oster 
    672   1.6    oster static void
    673   1.6    oster remove_hot_spare(fd, component)
    674   1.6    oster 	int fd;
    675   1.6    oster 	char *component;
    676   1.6    oster {
    677   1.6    oster 	RF_SingleComponent_t hot_spare;
    678   1.6    oster 	int component_num;
    679   1.6    oster 	int num_cols;
    680   1.5    oster 
    681   1.6    oster 	get_component_number(fd, component, &component_num, &num_cols);
    682   1.6    oster 
    683   1.6    oster 	hot_spare.row = component_num / num_cols;
    684   1.6    oster 	hot_spare.column = component_num % num_cols;
    685   1.6    oster 
    686   1.6    oster 	strncpy(hot_spare.component_name, component,
    687   1.6    oster 		sizeof(hot_spare.component_name));
    688   1.6    oster 
    689   1.6    oster 	do_ioctl( fd, RAIDFRAME_REMOVE_HOT_SPARE, &hot_spare,
    690   1.6    oster 		  "RAIDFRAME_REMOVE_HOT_SPARE");
    691   1.6    oster }
    692   1.6    oster 
    693   1.6    oster static void
    694   1.6    oster rebuild_in_place( fd, component )
    695   1.6    oster 	int fd;
    696   1.6    oster 	char *component;
    697   1.6    oster {
    698   1.6    oster 	RF_SingleComponent_t comp;
    699   1.6    oster 	int component_num;
    700   1.6    oster 	int num_cols;
    701   1.6    oster 
    702   1.6    oster 	get_component_number(fd, component, &component_num, &num_cols);
    703   1.6    oster 
    704   1.6    oster 	comp.row = 0;
    705   1.6    oster 	comp.column = component_num;
    706   1.6    oster 	strncpy(comp.component_name, component, sizeof(comp.component_name));
    707   1.6    oster 
    708   1.6    oster 	do_ioctl( fd, RAIDFRAME_REBUILD_IN_PLACE, &comp,
    709   1.6    oster 		  "RAIDFRAME_REBUILD_IN_PLACE");
    710  1.10    oster 
    711  1.10    oster 	if (verbose) {
    712  1.10    oster 		printf("Reconstruction status:\n");
    713  1.10    oster 		sleep(3); /* XXX give reconstruction a chance to start */
    714  1.19    oster 		do_meter(fd,RAIDFRAME_CHECK_RECON_STATUS_EXT);
    715  1.10    oster 	}
    716  1.10    oster 
    717  1.10    oster }
    718  1.10    oster 
    719  1.10    oster static void
    720  1.10    oster check_parity( fd, do_rewrite, dev_name )
    721  1.10    oster 	int fd;
    722  1.10    oster 	int do_rewrite;
    723  1.10    oster 	char *dev_name;
    724  1.10    oster {
    725  1.10    oster 	int is_clean;
    726  1.10    oster 	int percent_done;
    727  1.10    oster 
    728  1.10    oster 	is_clean = 0;
    729  1.10    oster 	percent_done = 0;
    730  1.10    oster 	do_ioctl(fd, RAIDFRAME_CHECK_PARITY, &is_clean,
    731  1.10    oster 		 "RAIDFRAME_CHECK_PARITY");
    732  1.10    oster 	if (is_clean) {
    733  1.10    oster 		printf("%s: Parity status: clean\n",dev_name);
    734  1.10    oster 	} else {
    735  1.10    oster 		printf("%s: Parity status: DIRTY\n",dev_name);
    736  1.10    oster 		if (do_rewrite) {
    737  1.10    oster 			printf("%s: Initiating re-write of parity\n",
    738  1.10    oster 			       dev_name);
    739  1.10    oster 			do_ioctl(fd, RAIDFRAME_REWRITEPARITY, NULL,
    740  1.10    oster 				 "RAIDFRAME_REWRITEPARITY");
    741  1.10    oster 			sleep(3); /* XXX give it time to
    742  1.10    oster 				     get started. */
    743  1.10    oster 			if (verbose) {
    744  1.10    oster 				printf("Parity Re-write status:\n");
    745  1.19    oster 				do_meter(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT);
    746  1.10    oster 			} else {
    747  1.10    oster 				do_ioctl(fd,
    748  1.10    oster 					 RAIDFRAME_CHECK_PARITYREWRITE_STATUS,
    749  1.10    oster 					 &percent_done,
    750  1.10    oster 					 "RAIDFRAME_CHECK_PARITYREWRITE_STATUS"
    751  1.10    oster 					 );
    752  1.10    oster 				while( percent_done < 100 ) {
    753  1.24    oster 					sleep(3); /* wait a bit... */
    754  1.10    oster 					do_ioctl(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS,
    755  1.10    oster 						 &percent_done, "RAIDFRAME_CHECK_PARITYREWRITE_STATUS");
    756  1.10    oster 				}
    757  1.10    oster 
    758  1.10    oster 			}
    759  1.10    oster 			       printf("%s: Parity Re-write complete\n",
    760  1.10    oster 				      dev_name);
    761  1.10    oster 		} else {
    762  1.10    oster 			/* parity is wrong, and is not being fixed.
    763  1.10    oster 			   Exit w/ an error. */
    764  1.10    oster 			exit(1);
    765  1.10    oster 		}
    766  1.10    oster 	}
    767  1.10    oster }
    768  1.10    oster 
    769  1.10    oster 
    770  1.10    oster static void
    771  1.14    oster check_status( fd, meter )
    772  1.10    oster 	int fd;
    773  1.14    oster 	int meter;
    774  1.10    oster {
    775  1.10    oster 	int recon_percent_done = 0;
    776  1.10    oster 	int parity_percent_done = 0;
    777  1.10    oster 	int copyback_percent_done = 0;
    778  1.10    oster 
    779  1.10    oster 	do_ioctl(fd, RAIDFRAME_CHECK_RECON_STATUS, &recon_percent_done,
    780  1.10    oster 		 "RAIDFRAME_CHECK_RECON_STATUS");
    781  1.10    oster 	printf("Reconstruction is %d%% complete.\n", recon_percent_done);
    782  1.10    oster 	do_ioctl(fd, RAIDFRAME_CHECK_PARITYREWRITE_STATUS,
    783  1.10    oster 		 &parity_percent_done,
    784  1.10    oster 		 "RAIDFRAME_CHECK_PARITYREWRITE_STATUS");
    785  1.10    oster 	printf("Parity Re-write is %d%% complete.\n", parity_percent_done);
    786  1.10    oster 	do_ioctl(fd, RAIDFRAME_CHECK_COPYBACK_STATUS, &copyback_percent_done,
    787  1.10    oster 		 "RAIDFRAME_CHECK_COPYBACK_STATUS");
    788  1.10    oster 	printf("Copyback is %d%% complete.\n", copyback_percent_done);
    789  1.10    oster 
    790  1.14    oster 	if (meter) {
    791  1.14    oster 		/* These 3 should be mutually exclusive at this point */
    792  1.14    oster 		if (recon_percent_done < 100) {
    793  1.14    oster 			printf("Reconstruction status:\n");
    794  1.19    oster 			do_meter(fd,RAIDFRAME_CHECK_RECON_STATUS_EXT);
    795  1.14    oster 		} else if (parity_percent_done < 100) {
    796  1.14    oster 			printf("Parity Re-write status:\n");
    797  1.19    oster 			do_meter(fd,RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT);
    798  1.14    oster 		} else if (copyback_percent_done < 100) {
    799  1.14    oster 			printf("Copyback status:\n");
    800  1.19    oster 			do_meter(fd,RAIDFRAME_CHECK_COPYBACK_STATUS_EXT);
    801  1.14    oster 		}
    802  1.10    oster 	}
    803  1.10    oster }
    804  1.10    oster 
    805  1.18  thorpej const char *tbits = "|/-\\";
    806  1.10    oster 
    807  1.10    oster static void
    808  1.17  thorpej do_meter(fd, option)
    809  1.10    oster 	int fd;
    810  1.17  thorpej 	u_long option;
    811  1.10    oster {
    812  1.10    oster 	int percent_done;
    813  1.19    oster 	int last_value;
    814  1.19    oster 	int start_value;
    815  1.19    oster 	RF_ProgressInfo_t progressInfo;
    816  1.19    oster 	void *pInfoPtr;
    817  1.10    oster 	struct timeval start_time;
    818  1.10    oster 	struct timeval last_time;
    819  1.10    oster 	struct timeval current_time;
    820  1.10    oster 	double elapsed;
    821  1.10    oster 	int elapsed_sec;
    822  1.10    oster 	int elapsed_usec;
    823  1.20    oster 	int simple_eta,last_eta;
    824  1.10    oster 	double rate;
    825  1.20    oster 	int amount;
    826  1.10    oster 	int tbit_value;
    827  1.10    oster 	int wait_for_more_data;
    828  1.10    oster 	char buffer[1024];
    829  1.10    oster 	char bar_buffer[1024];
    830  1.10    oster 	char eta_buffer[1024];
    831  1.10    oster 
    832  1.10    oster 	if (gettimeofday(&start_time,NULL)) {
    833  1.26      cgd 		fprintf(stderr,"%s: gettimeofday failed!?!?\n", getprogname());
    834  1.10    oster 		exit(errno);
    835  1.10    oster 	}
    836  1.19    oster 	memset(&progressInfo, 0, sizeof(RF_ProgressInfo_t));
    837  1.19    oster 	pInfoPtr=&progressInfo;
    838  1.19    oster 
    839  1.10    oster 	percent_done = 0;
    840  1.19    oster 	do_ioctl(fd, option, &pInfoPtr, "");
    841  1.19    oster 	last_value = progressInfo.completed;
    842  1.19    oster 	start_value = last_value;
    843  1.10    oster 	last_time = start_time;
    844  1.10    oster 	current_time = start_time;
    845  1.10    oster 
    846  1.10    oster 	wait_for_more_data = 0;
    847  1.10    oster 	tbit_value = 0;
    848  1.19    oster 	while(progressInfo.completed < progressInfo.total) {
    849  1.10    oster 
    850  1.19    oster 		percent_done = (progressInfo.completed * 100) /
    851  1.19    oster 			progressInfo.total;
    852  1.10    oster 
    853  1.10    oster 		get_bar(bar_buffer, percent_done, 40);
    854  1.10    oster 
    855  1.20    oster 		elapsed_sec = current_time.tv_sec - start_time.tv_sec;
    856  1.20    oster 		elapsed_usec = current_time.tv_usec - start_time.tv_usec;
    857  1.10    oster 		if (elapsed_usec < 0) {
    858  1.10    oster 			elapsed_usec-=1000000;
    859  1.10    oster 			elapsed_sec++;
    860  1.10    oster 		}
    861  1.20    oster 
    862  1.10    oster 		elapsed = (double) elapsed_sec +
    863  1.10    oster 			(double) elapsed_usec / 1000000.0;
    864  1.19    oster 
    865  1.20    oster 		amount = progressInfo.completed - start_value;
    866  1.19    oster 
    867  1.10    oster 		if (amount <= 0) { /* we don't do negatives (yet?) */
    868  1.10    oster 			amount = 0;
    869  1.10    oster 			wait_for_more_data = 1;
    870  1.10    oster 		} else {
    871  1.10    oster 			wait_for_more_data = 0;
    872  1.10    oster 		}
    873  1.20    oster 
    874  1.22    oster 		if (elapsed == 0)
    875  1.22    oster 			rate = 0.0;
    876  1.22    oster 		else
    877  1.22    oster 			rate = amount / elapsed;
    878  1.10    oster 
    879  1.10    oster 		if (rate > 0.0) {
    880  1.19    oster 			simple_eta = (int) (((double)progressInfo.total -
    881  1.20    oster 					     (double) progressInfo.completed)
    882  1.19    oster 					    / rate);
    883  1.10    oster 		} else {
    884  1.10    oster 			simple_eta = -1;
    885  1.10    oster 		}
    886  1.19    oster 
    887  1.10    oster 		if (simple_eta <=0) {
    888  1.10    oster 			simple_eta = last_eta;
    889  1.10    oster 		} else {
    890  1.10    oster 			last_eta = simple_eta;
    891  1.10    oster 		}
    892  1.10    oster 
    893  1.20    oster 		get_time_string(eta_buffer, simple_eta);
    894  1.10    oster 
    895  1.10    oster 		snprintf(buffer,1024,"\r%3d%% |%s| ETA: %s %c",
    896  1.10    oster 			 percent_done,bar_buffer,eta_buffer,tbits[tbit_value]);
    897  1.10    oster 
    898  1.10    oster 		write(fileno(stdout),buffer,strlen(buffer));
    899  1.10    oster 		fflush(stdout);
    900  1.10    oster 
    901  1.10    oster 		/* resolution wasn't high enough... wait until we get another
    902  1.10    oster 		   timestamp and perhaps more "work" done. */
    903  1.10    oster 
    904  1.10    oster 		if (!wait_for_more_data) {
    905  1.10    oster 			last_time = current_time;
    906  1.19    oster 			last_value = progressInfo.completed;
    907  1.10    oster 		}
    908  1.10    oster 
    909  1.10    oster 		if (++tbit_value>3)
    910  1.10    oster 			tbit_value = 0;
    911  1.10    oster 
    912  1.10    oster 		sleep(2);
    913  1.10    oster 
    914  1.10    oster 		if (gettimeofday(&current_time,NULL)) {
    915  1.10    oster 			fprintf(stderr,"%s: gettimeofday failed!?!?\n",
    916  1.26      cgd 				getprogname());
    917  1.10    oster 			exit(errno);
    918  1.10    oster 		}
    919  1.10    oster 
    920  1.19    oster 		do_ioctl( fd, option, &pInfoPtr, "");
    921  1.10    oster 
    922  1.10    oster 
    923  1.10    oster 	}
    924  1.10    oster 	printf("\n");
    925  1.10    oster }
    926  1.10    oster /* 40 '*''s per line, then 40 ' ''s line. */
    927  1.10    oster /* If you've got a screen wider than 160 characters, "tough" */
    928  1.10    oster 
    929  1.10    oster #define STAR_MIDPOINT 4*40
    930  1.10    oster const char stars[] = "****************************************"
    931  1.10    oster                      "****************************************"
    932  1.10    oster                      "****************************************"
    933  1.10    oster                      "****************************************"
    934  1.10    oster                      "                                        "
    935  1.10    oster                      "                                        "
    936  1.10    oster                      "                                        "
    937  1.10    oster                      "                                        "
    938  1.10    oster                      "                                        ";
    939  1.10    oster 
    940  1.10    oster static void
    941  1.10    oster get_bar(string,percent,max_strlen)
    942  1.10    oster 	char *string;
    943  1.10    oster 	double percent;
    944  1.10    oster 	int max_strlen;
    945  1.10    oster {
    946  1.10    oster 	int offset;
    947  1.10    oster 
    948  1.10    oster 	if (max_strlen > STAR_MIDPOINT) {
    949  1.10    oster 		max_strlen = STAR_MIDPOINT;
    950  1.10    oster 	}
    951  1.10    oster 	offset = STAR_MIDPOINT -
    952  1.10    oster 		(int)((percent * max_strlen)/ 100);
    953  1.10    oster 	if (offset < 0)
    954  1.10    oster 		offset = 0;
    955  1.10    oster 	snprintf(string,max_strlen,"%s",&stars[offset]);
    956  1.10    oster }
    957  1.10    oster 
    958  1.10    oster static void
    959  1.10    oster get_time_string(string,simple_time)
    960  1.10    oster 	char *string;
    961  1.10    oster 	int simple_time;
    962  1.10    oster {
    963  1.10    oster 	int minutes, seconds, hours;
    964  1.10    oster 	char hours_buffer[5];
    965  1.10    oster 	char minutes_buffer[5];
    966  1.10    oster 	char seconds_buffer[5];
    967  1.10    oster 
    968  1.10    oster 	if (simple_time >= 0) {
    969  1.10    oster 
    970  1.10    oster 		minutes = (int) simple_time / 60;
    971  1.10    oster 		seconds = ((int)simple_time - 60*minutes);
    972  1.10    oster 		hours = minutes / 60;
    973  1.10    oster 		minutes = minutes - 60*hours;
    974  1.10    oster 
    975  1.10    oster 		if (hours > 0) {
    976  1.10    oster 			snprintf(hours_buffer,5,"%02d:",hours);
    977  1.10    oster 		} else {
    978  1.10    oster 			snprintf(hours_buffer,5,"   ");
    979  1.10    oster 		}
    980  1.10    oster 
    981  1.10    oster 		snprintf(minutes_buffer,5,"%02d:",minutes);
    982  1.10    oster 		snprintf(seconds_buffer,5,"%02d",seconds);
    983  1.10    oster 		snprintf(string,1024,"%s%s%s",
    984  1.10    oster 			 hours_buffer, minutes_buffer, seconds_buffer);
    985  1.10    oster 	} else {
    986  1.10    oster 		snprintf(string,1024,"   --:--");
    987  1.10    oster 	}
    988  1.10    oster 
    989   1.5    oster }
    990   1.5    oster 
    991   1.5    oster static void
    992   1.1    oster usage()
    993   1.1    oster {
    994  1.26      cgd 	const char *progname = getprogname();
    995  1.26      cgd 
    996  1.26      cgd 	fprintf(stderr, "usage: %s [-v] -a component dev\n", progname);
    997  1.26      cgd 	fprintf(stderr, "       %s [-v] -A yes | no | root dev\n", progname);
    998  1.26      cgd 	fprintf(stderr, "       %s [-v] -B dev\n", progname);
    999  1.26      cgd 	fprintf(stderr, "       %s [-v] -c config_file dev\n", progname);
   1000  1.26      cgd 	fprintf(stderr, "       %s [-v] -C config_file dev\n", progname);
   1001  1.26      cgd 	fprintf(stderr, "       %s [-v] -f component dev\n", progname);
   1002  1.26      cgd 	fprintf(stderr, "       %s [-v] -F component dev\n", progname);
   1003  1.26      cgd 	fprintf(stderr, "       %s [-v] -g component dev\n", progname);
   1004  1.26      cgd 	fprintf(stderr, "       %s [-v] -i dev\n", progname);
   1005  1.26      cgd 	fprintf(stderr, "       %s [-v] -I serial_number dev\n", progname);
   1006  1.26      cgd 	fprintf(stderr, "       %s [-v] -r component dev\n", progname);
   1007  1.26      cgd 	fprintf(stderr, "       %s [-v] -R component dev\n", progname);
   1008  1.26      cgd 	fprintf(stderr, "       %s [-v] -s dev\n", progname);
   1009  1.26      cgd 	fprintf(stderr, "       %s [-v] -S dev\n", progname);
   1010  1.26      cgd 	fprintf(stderr, "       %s [-v] -u dev\n", progname);
   1011   1.6    oster #if 0
   1012  1.26      cgd 	fprintf(stderr, "usage: %s %s\n", progname,
   1013   1.6    oster 		"-a | -f | -F | -g | -r | -R component dev");
   1014  1.26      cgd 	fprintf(stderr, "       %s -B | -i | -s | -S -u dev\n", progname);
   1015  1.26      cgd 	fprintf(stderr, "       %s -c | -C config_file dev\n", progname);
   1016  1.26      cgd 	fprintf(stderr, "       %s -I serial_number dev\n", progname);
   1017   1.5    oster #endif
   1018   1.1    oster 	exit(1);
   1019   1.1    oster 	/* NOTREACHED */
   1020   1.1    oster }
   1021