strcpy(cdev, dev); cdev[strlen(cdev)-1] = 'c';
main(argc, argv)	int argc;	char *argv[];{	int	c;	int	devfd;	char	*protostore;	long	protosize;	while ((c = getopt(argc, argv, "vnh")) != -1) {		switch (c) {		case 'h':			/* Don't strip a.out header */			hflag = 1;			break;		case 'n':			/* Do not actually write the bootblock to disk */			nowrite = 1;			break;		case 'v':			/* Chat */			verbose = 1;			break;		default:			usage();		}	}	if (argc - optind < 3) {		usage();	}	boot = argv[optind];	proto = argv[optind + 1];	dev = argv[optind + 2];	if (verbose) {		printf("boot: %s\n", boot);		printf("proto: %s\n", proto);		printf("device: %s\n", dev);	}	/* Load proto blocks into core */	if ((protostore = loadprotoblocks(proto, &protosize)) == NULL)		exit(1);	/* XXX - Paranoia: Make sure size is aligned! */	if (protosize & (DEV_BSIZE - 1))		err(1, "proto bootblock bad size=%d", protosize);	/* Open and check raw disk device */	if ((devfd = open(dev, O_RDONLY, 0)) < 0)		err(1, "open: %s", dev);	/* Extract and load block numbers */	if (loadblocknums(boot, devfd) != 0)		exit(1);	(void)close(devfd);	if (nowrite)		return 0;	/* Write patched proto bootblocks into the superblock */	if (protosize > SBSIZE - DEV_BSIZE)		errx(1, "proto bootblocks too big");	if ((devfd = open(dev, O_RDWR, 0)) < 0)		err(1, "open: %s", dev);	if (lseek(devfd, DEV_BSIZE, SEEK_SET) != DEV_BSIZE)		err(1, "lseek bootstrap");	/* Sync filesystems (to clean in-memory superblock?) */	sync();	if (write(devfd, protostore, protosize) != protosize)		err(1, "write bootstrap");	(void)close(devfd);	return 0;}