[Midnightbsd-cvs] src: src/sbin: Remove mca which was only used for ia64.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Nov 11 16:29:40 EST 2008


Log Message:
-----------
Remove mca which was only used for ia64.  

Add recoverdisk, a handy utility for hard drives and optical media.

Sync idmapd with freebsd 7.

Switch to the new world order.

Modified Files:
--------------
    src/sbin:
        Makefile (r1.5 -> r1.6)
        Makefile.inc (r1.2 -> r1.3)
    src/sbin/idmapd:
        Makefile (r1.1.1.1 -> r1.2)
        idmapd.8 (r1.1.1.1 -> r1.2)
        idmapd.c (r1.1.1.2 -> r1.2)

Added Files:
-----------
    src/sbin/recoverdisk:
        Makefile (r1.1)
        recoverdisk.1 (r1.1)
        recoverdisk.c (r1.1)

Removed Files:
-------------
    src/sbin/mca:
        Makefile
        mca.c

-------------- next part --------------
Index: Makefile.inc
===================================================================
RCS file: /home/cvs/src/sbin/Makefile.inc,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sbin/Makefile.inc -L sbin/Makefile.inc -u -r1.2 -r1.3
--- sbin/Makefile.inc
+++ sbin/Makefile.inc
@@ -1,10 +1,12 @@
 #	@(#)Makefile.inc	8.1 (Berkeley) 6/8/93
-# $FreeBSD: src/sbin/Makefile.inc,v 1.14 2004/12/21 09:59:42 ru Exp $
+# $FreeBSD: src/sbin/Makefile.inc,v 1.15 2006/03/17 18:54:30 ru Exp $
 # $MidnightBSD$
 
+.include <bsd.own.mk>
+
 BINDIR?=	/sbin
 WARNS?=	2
 
-.if defined(NO_DYNAMICROOT)
+.if ${MK_DYNAMICROOT} == "no"
 NO_SHARED?=	YES
 .endif
Index: Makefile
===================================================================
RCS file: /home/cvs/src/sbin/Makefile,v
retrieving revision 1.5
retrieving revision 1.6
diff -L sbin/Makefile -L sbin/Makefile -u -r1.5 -r1.6
--- sbin/Makefile
+++ sbin/Makefile
@@ -1,6 +1,9 @@
 #	@(#)Makefile	8.5 (Berkeley) 3/31/94
-# $FreeBSD: src/sbin/Makefile,v 1.156.2.1 2005/12/15 23:30:11 pjd Exp $
+# $FreeBSD: src/sbin/Makefile,v 1.168 2007/07/24 15:35:00 scottl Exp $
 # $MidnightBSD$
+
+.include <bsd.own.mk>
+
 # XXX MISSING:		icheck ncheck
 
 SUBDIR=	adjkerntz \
@@ -33,17 +36,17 @@
 	gpt \
 	growfs \
 	gvinum \
+	idmapd \
 	ifconfig \
 	init \
-	${_ip6fw} \
 	${_ipf} \
 	ipfw \
+	iscontrol \
 	kldconfig \
 	kldload \
 	kldstat \
 	kldunload \
 	ldconfig \
-	${_mca} \
 	md5 \
 	mdconfig \
 	mdmfs \
@@ -51,14 +54,10 @@
 	mksnap_ffs \
 	mount \
 	mount_cd9660 \
-	mount_ext2fs \
 	mount_msdosfs \
 	mount_nfs \
-	mount_nfs4 \
 	mount_ntfs \
 	mount_nullfs \
-	mount_reiserfs \
-	mount_std \
 	mount_udf \
 	mount_unionfs \
 	natd \
@@ -73,10 +72,11 @@
 	quotacheck \
 	rcorder \
 	reboot \
+	recoverdisk \
 	restore \
 	route \
 	routed \
-	rtsol \
+	${_rtsol} \
 	savecore \
 	${_sconfig} \
 	setkey \
@@ -90,34 +90,31 @@
 	tunefs \
 	umount \
 
-.if !defined(NO_ATM)
+.if ${MK_ATM} != "no"
 _atm=		atm
 .endif
 
-.if !defined(NO_CXX)
+.if ${MK_CXX} != "no"
 _devd=		devd
 .endif
 
-.if !defined(NO_IPFILTER)
+.if ${MK_IPFILTER} != "no"
 _ipf=		ipf
 .endif
 
-.if !defined(NO_PF)
+.if ${MK_PF} != "no"
 _pfctl=		pfctl
 _pflogd=	pflogd
 .endif
 
-.if !defined(NO_INET6)
-_ip6fw=		ip6fw
+.if ${MK_INET6} != "no"
 _ping6=		ping6
+_rtsol=		rtsol
 .endif
 
 .if ${MACHINE_ARCH} == "i386"
 .if ${MACHINE} == "i386"
 _fdisk=		fdisk
-.elif ${MACHINE} == "pc98"
-_fdisk_pc98=	fdisk_pc98
-.endif
 _sconfig=	sconfig
 .endif
 
@@ -125,9 +122,4 @@
 _fdisk=		fdisk
 .endif
 
-.if ${MACHINE_ARCH} == "ia64"
-_fdisk=		fdisk
-_mca=		mca
-.endif
-
 .include <bsd.subdir.mk>
Index: idmapd.8
===================================================================
RCS file: /home/cvs/src/sbin/idmapd/idmapd.8,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sbin/idmapd/idmapd.8 -L sbin/idmapd/idmapd.8 -u -r1.1.1.1 -r1.2
--- sbin/idmapd/idmapd.8
+++ sbin/idmapd/idmapd.8
@@ -20,9 +20,10 @@
 .\" connection with the use of the software, even if it has been or is hereafter
 .\" advised of the possibility of such damages.
 .\"
-.\" $FreeBSD: src/sbin/idmapd/idmapd.8,v 1.4 2005/01/21 10:27:44 ru Exp $
+.\" $FreeBSD: src/sbin/idmapd/idmapd.8,v 1.5 2006/10/15 13:50:16 ceri Exp $
+.\" $MidnightBSD$
 .\"
-.Dd November 14, 2003
+.Dd October 15, 2006
 .Dt IDMAPD 8
 .Os
 .Sh NAME
@@ -37,7 +38,7 @@
 .Nm
 daemon normally runs in the background and services UID/GID-to-name and
 name-to-UID/GID mapping
-requests from the NFSv4 client.
+requests from the NFSv4 client kernel threads.
 .Pp
 The options are:
 .Bl -tag -width indent
@@ -60,4 +61,4 @@
 .Sh SEE ALSO
 .Xr getpwnam 3 ,
 .Xr getpwuid 3 ,
-.Xr mount_nfs 8
+.Xr mount_nfs4 8
Index: idmapd.c
===================================================================
RCS file: /home/cvs/src/sbin/idmapd/idmapd.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sbin/idmapd/idmapd.c -L sbin/idmapd/idmapd.c -u -r1.1.1.2 -r1.2
--- sbin/idmapd/idmapd.c
+++ sbin/idmapd/idmapd.c
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* $FreeBSD: src/sbin/idmapd/idmapd.c,v 1.6 2005/04/14 20:27:30 rees Exp $ */
 /* $Id: idmapd.c,v 1.5 2003/11/05 14:58:58 rees Exp $ */
 
Index: Makefile
===================================================================
RCS file: /home/cvs/src/sbin/idmapd/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sbin/idmapd/Makefile -L sbin/idmapd/Makefile -u -r1.1.1.1 -r1.2
--- sbin/idmapd/Makefile
+++ sbin/idmapd/Makefile
@@ -1,13 +1,11 @@
 #	@(#)Makefile	8.2 (Berkeley) 3/27/94
-#
-# $FreeBSD: src/sbin/idmapd/Makefile,v 1.3 2005/01/28 16:08:06 ru Exp $
+# $FreeBSD: src/sbin/idmapd/Makefile,v 1.4 2006/10/15 13:51:49 ceri Exp $
+# $MidnightBSD$
 
 PROG=	idmapd
 MAN=	idmapd.8
 
-CFLAGS+= -DNFS -I/usr/src/sys
+CFLAGS+= -DNFS -I${.CURDIR}/../../sys
 WARNS?=	2
 
-.PATH:
-
 .include <bsd.prog.mk>
--- sbin/mca/mca.c
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- * Copyright (c) 2002 Marcel Moolenaar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sbin/mca/mca.c,v 1.3 2002/11/01 06:34:35 marcel Exp $");
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/sysctl.h>
-#include <sys/uuid.h>
-
-/*
- * Hack to make this compile on non-ia64 machines.
- */
-#ifdef __ia64__
-#include <machine/mca.h>
-#else
-#include "../../sys/ia64/include/mca.h"
-#endif
-
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <uuid.h>
-
-#define	BCD(x)	((x >> 4) * 10 + (x & 15))
-
-static char hw_mca_count[] = "hw.mca.count";
-static char hw_mca_first[] = "hw.mca.first";
-static char hw_mca_last[] = "hw.mca.last";
-static char hw_mca_recid[] = "hw.mca.%d";
-
-static char default_dumpfile[] = "/var/log/mca.log";
-
-int fl_dump;
-char *file;
-
-static const char *
-severity(int error)
-{
-
-	switch (error) {
-	case MCA_RH_ERROR_RECOVERABLE:
-		return ("recoverable");
-	case MCA_RH_ERROR_FATAL:
-		return ("fatal");
-	case MCA_RH_ERROR_CORRECTED:
-		return ("corrected");
-	}
-
-	return ("unknown");
-}
-
-static const char *
-uuid(uuid_t *id)
-{
-	static char buffer[64];
-	char *s;
-
-	uuid_to_string(id, &s, NULL);
-	strcpy(buffer, s);
-	free(s);
-	return (buffer);
-}
-
-static int
-show_value(int indent, const char *var, const char *fmt, ...)
-{
-	va_list ap;
-	int len;
-
-	len = indent;
-	while (indent--)
-		putchar(' ');
-	len += printf("<%s>", var);
-	va_start(ap, fmt);
-	len += vprintf(fmt, ap);
-	len += printf("</%s>\n", var);
-	return (len);
-}
-
-static size_t
-show_header(struct mca_record_header *rh)
-{
-
-	printf("  <header>\n");
-	show_value(4, "seqnr", "%lld", (long long)rh->rh_seqnr);
-	show_value(4, "revision", "%d.%d", BCD(rh->rh_major),
-	    BCD(rh->rh_minor));
-	show_value(4, "severity", "%s", severity(rh->rh_error));
-	show_value(4, "length", "%lld", (long long)rh->rh_length);
-	show_value(4, "date", "%d%02d/%02d/%02d",
-	    BCD(rh->rh_time[MCA_RH_TIME_CENT]),
-	    BCD(rh->rh_time[MCA_RH_TIME_YEAR]),
-	    BCD(rh->rh_time[MCA_RH_TIME_MON]),
-	    BCD(rh->rh_time[MCA_RH_TIME_MDAY]));
-	show_value(4, "time", "%02d:%02d:%02d",
-	    BCD(rh->rh_time[MCA_RH_TIME_HOUR]),
-	    BCD(rh->rh_time[MCA_RH_TIME_MIN]),
-	    BCD(rh->rh_time[MCA_RH_TIME_SEC]));
-	if (rh->rh_flags & MCA_RH_FLAGS_PLATFORM_ID)
-		show_value(4, "platform", "%s", uuid(&rh->rh_platform));
-	printf("  </header>\n");
-	return (rh->rh_length);
-}
-
-static void
-show_cpu_mod(const char *what, int idx, struct mca_cpu_mod *cpu_mod)
-{
-	printf("      <%s-%d>\n", what, idx);
-	if (cpu_mod->cpu_mod_flags & MCA_CPU_MOD_FLAGS_INFO)
-		show_value(8, "info", "0x%016llx",
-		    (long long)cpu_mod->cpu_mod_info);
-	if (cpu_mod->cpu_mod_flags & MCA_CPU_MOD_FLAGS_REQID)
-		show_value(8, "requester", "0x%016llx",
-		    (long long)cpu_mod->cpu_mod_reqid);
-	if (cpu_mod->cpu_mod_flags & MCA_CPU_MOD_FLAGS_RSPID)
-		show_value(8, "responder", "0x%016llx",
-		    (long long)cpu_mod->cpu_mod_rspid);
-	if (cpu_mod->cpu_mod_flags & MCA_CPU_MOD_FLAGS_TGTID)
-		show_value(8, "target", "0x%016llx",
-		    (long long)cpu_mod->cpu_mod_tgtid);
-	if (cpu_mod->cpu_mod_flags & MCA_CPU_MOD_FLAGS_IP)
-		show_value(8, "ip", "0x%016llx",
-		    (long long)cpu_mod->cpu_mod_ip);
-	printf("      </%s-%d>\n", what, idx);
-}
-
-static void
-show_cpu(struct mca_cpu_record *cpu)
-{
-	char var[16];
-	struct mca_cpu_mod *mod;
-	struct mca_cpu_cpuid *cpuid;
-	struct mca_cpu_psi *psi;
-	int i, n;
-
-	printf("    <cpu>\n");
-
-	if (cpu->cpu_flags & MCA_CPU_FLAGS_ERRMAP)
-		show_value(6, "errmap", "0x%016llx",
-		    (long long)cpu->cpu_errmap);
-	if (cpu->cpu_flags & MCA_CPU_FLAGS_STATE)
-		show_value(6, "state", "0x%016llx",
-		    (long long)cpu->cpu_state);
-	if (cpu->cpu_flags & MCA_CPU_FLAGS_CR_LID)
-		show_value(6, "cr_lid", "0x%016llx",
-		    (long long)cpu->cpu_cr_lid);
-
-	mod = (struct mca_cpu_mod*)(cpu + 1);
-	n = MCA_CPU_FLAGS_CACHE(cpu->cpu_flags);
-	for (i = 0; i < n; i++)
-		show_cpu_mod("cache", i, mod++);
-	n = MCA_CPU_FLAGS_TLB(cpu->cpu_flags);
-	for (i = 0; i < n; i++)
-		show_cpu_mod("tlb", i, mod++);
-	n = MCA_CPU_FLAGS_BUS(cpu->cpu_flags);
-	for (i = 0; i < n; i++)
-		show_cpu_mod("bus", i, mod++);
-	n = MCA_CPU_FLAGS_REG(cpu->cpu_flags);
-	for (i = 0; i < n; i++)
-		show_cpu_mod("reg", i, mod++);
-	n = MCA_CPU_FLAGS_MS(cpu->cpu_flags);
-	for (i = 0; i < n; i++)
-		show_cpu_mod("ms", i, mod++);
-
-	cpuid = (struct mca_cpu_cpuid*)mod;
-	for (i = 0; i < 6; i++) {
-		sprintf(var, "cpuid-%d", i);
-		show_value(6, var, "0x%016llx", (long long)cpuid->cpuid[i]);
-	}
-
-	psi = (struct mca_cpu_psi*)(cpuid + 1);
-	/* TODO: Dump PSI */
-
-	printf("    </cpu>\n");
-}
-
-static void
-show_memory(struct mca_mem_record *mem)
-{
-	printf("    <memory>\n");
-
-	if (mem->mem_flags & MCA_MEM_FLAGS_STATUS)
-		show_value(6, "status", "0x%016llx",
-		    (long long)mem->mem_status);
-	if (mem->mem_flags & MCA_MEM_FLAGS_ADDR)
-		show_value(6, "address", "0x%016llx",
-		    (long long)mem->mem_addr);
-	if (mem->mem_flags & MCA_MEM_FLAGS_ADDRMASK)
-		show_value(6, "mask", "0x%016llx",
-		    (long long)mem->mem_addrmask);
-	if (mem->mem_flags & MCA_MEM_FLAGS_NODE)
-		show_value(6, "node", "0x%04x", mem->mem_node);
-	if (mem->mem_flags & MCA_MEM_FLAGS_CARD)
-		show_value(6, "card", "0x%04x", mem->mem_card);
-	if (mem->mem_flags & MCA_MEM_FLAGS_MODULE)
-		show_value(6, "module", "0x%04x", mem->mem_module);
-	if (mem->mem_flags & MCA_MEM_FLAGS_BANK)
-		show_value(6, "bank", "0x%04x", mem->mem_bank);
-	if (mem->mem_flags & MCA_MEM_FLAGS_DEVICE)
-		show_value(6, "device", "0x%04x", mem->mem_device);
-	if (mem->mem_flags & MCA_MEM_FLAGS_ROW)
-		show_value(6, "row", "0x%04x", mem->mem_row);
-	if (mem->mem_flags & MCA_MEM_FLAGS_COLUMN)
-		show_value(6, "column", "0x%04x", mem->mem_column);
-	if (mem->mem_flags & MCA_MEM_FLAGS_BITPOS)
-		show_value(6, "bit", "0x%04x", mem->mem_bitpos);
-	if (mem->mem_flags & MCA_MEM_FLAGS_REQID)
-		show_value(6, "requester", "0x%016llx",
-		    (long long)mem->mem_reqid);
-	if (mem->mem_flags & MCA_MEM_FLAGS_RSPID)
-		show_value(6, "responder", "0x%016llx",
-		    (long long)mem->mem_rspid);
-	if (mem->mem_flags & MCA_MEM_FLAGS_TGTID)
-		show_value(6, "target", "0x%016llx",
-		    (long long)mem->mem_tgtid);
-	if (mem->mem_flags & MCA_MEM_FLAGS_BUSDATA)
-		show_value(6, "status", "0x%016llx",
-		    (long long)mem->mem_busdata);
-	if (mem->mem_flags & MCA_MEM_FLAGS_OEM_ID)
-		show_value(6, "oem", "%s", uuid(&mem->mem_oem_id));
-	/* TODO: Dump OEM data */
-
-	printf("    </memory>\n");
-}
-
-static void
-show_sel(void)
-{
-	printf("    # SEL\n");
-}
-
-static void
-show_pci_bus(struct mca_pcibus_record *pcibus)
-{
-	printf("    <pci-bus>\n");
-
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_STATUS)
-		show_value(6, "status", "0x%016llx",
-		    (long long)pcibus->pcibus_status);
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_ERROR)
-		show_value(6, "error", "0x%04x", pcibus->pcibus_error);
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_BUS)
-		show_value(6, "bus", "0x%04x", pcibus->pcibus_bus);
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_ADDR)
-		show_value(6, "address", "0x%016llx",
-		    (long long)pcibus->pcibus_addr);
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_DATA)
-		show_value(6, "data", "0x%016llx",
-		    (long long)pcibus->pcibus_data);
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_CMD)
-		show_value(6, "cmd", "0x%016llx",
-		    (long long)pcibus->pcibus_cmd);
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_REQID)
-		show_value(6, "requester", "0x%016llx",
-		    (long long)pcibus->pcibus_reqid);
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_RSPID)
-		show_value(6, "responder", "0x%016llx",
-		    (long long)pcibus->pcibus_rspid);
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_TGTID)
-		show_value(6, "target", "0x%016llx",
-		    (long long)pcibus->pcibus_tgtid);
-	if (pcibus->pcibus_flags & MCA_PCIBUS_FLAGS_OEM_ID)
-		show_value(6, "oem", "%s", uuid(&pcibus->pcibus_oem_id));
-	/* TODO: Dump OEM data */
-
-	printf("    </pci-bus>\n");
-}
-
-static void
-show_smbios(void)
-{
-	printf("    # SMBIOS\n");
-}
-
-static void
-show_pci_dev(struct mca_pcidev_record *pcidev)
-{
-	printf("    <pci-dev>\n");
-
-	if (pcidev->pcidev_flags & MCA_PCIDEV_FLAGS_STATUS)
-		show_value(6, "status", "0x%016llx",
-		    (long long)pcidev->pcidev_status);
-	if (pcidev->pcidev_flags & MCA_PCIDEV_FLAGS_INFO) {
-		show_value(6, "vendor", "0x%04x",
-		    pcidev->pcidev_info.info_vendor);
-		show_value(6, "device", "0x%04x",
-		    pcidev->pcidev_info.info_device);
-		show_value(6, "class", "0x%06x",
-		    MCA_PCIDEV_INFO_CLASS(pcidev->pcidev_info.info_ccfn));
-		show_value(6, "function", "0x%02x",
-		    MCA_PCIDEV_INFO_FUNCTION(pcidev->pcidev_info.info_ccfn));
-		show_value(6, "slot", "0x%02x", pcidev->pcidev_info.info_slot);
-		show_value(6, "bus", "0x%04x", pcidev->pcidev_info.info_bus);
-		show_value(6, "segment", "0x%04x",
-		    pcidev->pcidev_info.info_segment);
-	}
-	/* TODO: dump registers */
-	/* TODO: Dump OEM data */
-
-	printf("    </pci-dev>\n");
-}
-
-static void
-show_generic(void)
-{
-	printf("    # GENERIC\n");
-}
-
-static size_t
-show_section(struct mca_section_header *sh)
-{
-	static uuid_t uuid_cpu = MCA_UUID_CPU;
-	static uuid_t uuid_memory = MCA_UUID_MEMORY;
-	static uuid_t uuid_sel = MCA_UUID_SEL;
-	static uuid_t uuid_pci_bus = MCA_UUID_PCI_BUS;
-	static uuid_t uuid_smbios = MCA_UUID_SMBIOS;
-	static uuid_t uuid_pci_dev = MCA_UUID_PCI_DEV;
-	static uuid_t uuid_generic = MCA_UUID_GENERIC;
-
-	printf("  <section>\n");
-	show_value(4, "uuid", "%s", uuid(&sh->sh_uuid));
-	show_value(4, "revision", "%d.%d", BCD(sh->sh_major),
-	    BCD(sh->sh_minor));
-
-	if (uuid_equal(&sh->sh_uuid, &uuid_cpu, NULL))
-		show_cpu((void*)(sh + 1));
-	else if (uuid_equal(&sh->sh_uuid, &uuid_memory, NULL))
-		show_memory((void*)(sh + 1));
-	else if (uuid_equal(&sh->sh_uuid, &uuid_sel, NULL))
-		show_sel();
-	else if (uuid_equal(&sh->sh_uuid, &uuid_pci_bus, NULL))
-		show_pci_bus((void*)(sh + 1));
-	else if (uuid_equal(&sh->sh_uuid, &uuid_smbios, NULL))
-		show_smbios();
-	else if (uuid_equal(&sh->sh_uuid, &uuid_pci_dev, NULL))
-		show_pci_dev((void*)(sh + 1));
-	else if (uuid_equal(&sh->sh_uuid, &uuid_generic, NULL))
-		show_generic();
-
-	printf("  </section>\n");
-	return (sh->sh_length);
-}
-
-static void
-show(char *data)
-{
-	size_t reclen, seclen;
-
-	printf("<record>\n");
-	reclen = show_header((void*)data) - sizeof(struct mca_record_header);
-	data += sizeof(struct mca_record_header);
-	while (reclen > sizeof(struct mca_section_header)) {
-		seclen = show_section((void*)data);
-		reclen -= seclen;
-		data += seclen;
-	}
-	printf("</record>\n");
-}
-
-static void
-showall(char *buf, size_t buflen)
-{
-	struct mca_record_header *rh;
-	size_t reclen;
-
-	do {
-		if (buflen < sizeof(struct mca_record_header))
-			return;
-
-		rh = (void*)buf;
-		reclen = rh->rh_length;
-		if (buflen < reclen)
-			return;
-
-		show(buf);
-
-		buf += reclen;
-		buflen -= reclen;
-	}
-	while (1);
-}
-
-static void
-dump(char *data)
-{
-	struct mca_record_header *rh;
-	const char *fn;
-	int fd;
-
-	rh = (void*)data;
-	fn = (file) ? file : default_dumpfile;
-	fd = open(fn, O_WRONLY|O_CREAT|O_APPEND, 0660);
-	if (fd == -1)
-		err(2, "open(%s)", fn);
-	if (write(fd, (void*)rh, rh->rh_length) == -1)
-		err(2, "write(%s)", fn);
-	close(fd);
-}
-
-static void
-usage(void)
-{
-
-	fprintf(stderr, "usage: mca [-df]\n");
-	exit (1);
-}
-
-int
-main(int argc, char **argv)
-{
-	char mib[32];
-	char *buf;
-	size_t len;
-	int ch, error, fd;
-	int count, first, last;
-
-	while ((ch = getopt(argc, argv, "df:")) != -1) {
-		switch(ch) {
-		case 'd':	/* dump */
-			fl_dump = 1;
-			break;
-		case 'f':
-			if (file)
-				free(file);		/* XXX complain! */
-			file = strdup(optarg);
-			break;
-		default:
-			usage();
-		}
-	}
-
-	argc -= optind;
-	argv += optind;
-
-	if (file == NULL || fl_dump) {
-		len = sizeof(count);
-		error = sysctlbyname(hw_mca_count, &count, &len, NULL, 0);
-		if (error)
-			err(1, hw_mca_count);
-
-		if (count == 0)
-			errx(0, "no error records found");
-
-		len = sizeof(first);
-		error = sysctlbyname(hw_mca_first, &first, &len, NULL, 0);
-		if (error)
-			err(1, hw_mca_first);
-
-		len = sizeof(last);
-		error = sysctlbyname(hw_mca_last, &last, &len, NULL, 0);
-		if (error)
-			err(1, hw_mca_last);
-
-		while (count && first <= last) {
-			sprintf(mib, hw_mca_recid, first);
-			len = 0;
-			error = sysctlbyname(mib, NULL, &len, NULL, 0);
-			if (error == ENOENT) {
-				first++;
-				continue;
-			}
-			if (error)
-				err(1, "%s(1)", mib);
-
-			buf = malloc(len);
-			if (buf == NULL)
-				err(1, "buffer");
-
-			error = sysctlbyname(mib, buf, &len, NULL, 0);
-			if (error)
-				err(1, "%s(2)", mib);
-
-			if (fl_dump)
-				dump(buf);
-			else
-				show(buf);
-
-			free(buf);
-			first++;
-			count--;
-		}
-	} else {
-		fd = open(file, O_RDONLY);
-		if (fd == -1)
-			err(1, "open(%s)", file);
-
-		len = lseek(fd, 0LL, SEEK_END);
-		buf = mmap(NULL, len, PROT_READ, 0U, fd, 0LL);
-		if (buf == MAP_FAILED)
-			err(1, "mmap(%s)", file);
-
-		showall(buf, len);
-
-		munmap(buf, len);
-		close(fd);
-	}
-
-	return (0);
-}
--- sbin/mca/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD: src/sbin/mca/Makefile,v 1.4 2004/12/21 08:47:08 ru Exp $
-PROG=	mca
-WARNS?=	4
-NO_MAN=
-
-.include <bsd.prog.mk>
--- /dev/null
+++ sbin/recoverdisk/recoverdisk.1
@@ -0,0 +1,134 @@
+.\" Copyright (c) 2006 Ulrich Spoerlein <uspoerlein at gmail.com>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $MidnightBSD: src/sbin/recoverdisk/recoverdisk.1,v 1.1 2008/11/11 21:29:37 laffer1 Exp $
+.\" $FreeBSD: src/sbin/recoverdisk/recoverdisk.1,v 1.3 2007/06/17 16:53:45 phk Exp $
+.\"
+.Dd May 6, 2006
+.Dt RECOVERDISK 1
+.Os
+.Sh NAME
+.Nm recoverdisk
+.Nd recover data from hard disk or optical media
+.Sh SYNOPSIS
+.Nm
+.Op Fl r Ar rlist
+.Op Fl w Ar wlist
+.Ar special
+.Op Ar file
+.Sh DESCRIPTION
+The
+.Nm
+utility reads data from the
+.Ar special
+file until all blocks could be successfully read.
+It starts reading in multiples of the sector size.
+Whenever a block fails, it is put to the end of the working queue and will be
+read again, possibly with a smaller read size.
+.Pp
+It uses block sizes of roughly 1 MB, 64kB, and the native sector size (usually
+512 bytes).
+These figures are adjusted slightly, for devices whose sectorsize is not a
+power of 2, e.g., audio CDs with a sector size of 2352 bytes.
+.Pp
+The options are as follows:
+.Bl -tag -width indent
+.It Fl r Ar rlist
+Read the list of blocks and block sizes to read from the specified file.
+.It Fl w Ar wlist
+Write the list of remaining blocks to read to the specified file if
+.Nm
+is aborted via
+.Dv SIGINT .
+.El
+.Pp
+The
+.Fl r
+and
+.Fl w
+options can be specified together.
+Especially, they can point to the same file, which will be updated on abort.
+.Sh OUTPUT
+The
+.Nm
+utility
+prints several columns, detailing the progress
+.Bl -tag -width remaining
+.It Va start
+Starting offset of the current block.
+.It Va size
+Read size of the current block.
+.It Va len
+Length of the current block.
+.It Va state
+Is increased for every failed read.
+.It Va done
+Number of bytes already read.
+.It Va remaining
+Number of bytes remaining.
+.It Va "% done"
+Percent complete.
+.El
+.Sh EXAMPLES
+.Bd -literal
+# recover data from failing hard drive ad3
+touch /data/lots_of_space
+recoverdisk /dev/ad3 /data/lots_of_space
+
+# clone a hard disk
+recoverdisk /dev/ad3 /dev/ad4
+
+# read an ISO image from a CD-ROM
+touch /data/cd.iso; recoverdisk /dev/acd0 /data/cd.iso
+
+# continue reading from a broken CD and update the existing worklist
+recoverdisk -r worklist -w worklist /dev/acd0 /data/cd.iso
+
+# recover a single file from the unreadable media
+touch file.avi; recoverdisk /cdrom/file.avi file.avi
+.Ed
+.Sh SEE ALSO
+.Xr dd 1
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 7.0 .
+.Sh AUTHORS
+.An -nosplit
+The original implementation was done by
+.An Poul-Henning Kamp Aq phk at FreeBSD.org
+with minor improvements from
+.An Ulrich Sp\(:orlein Aq uspoerlein at gmail.com .
+.Pp
+This manual page was written by
+.An Ulrich Sp\(:orlein .
+.Sh BUGS
+Reading from media where the sectorsize is not a power of 2 will make all
+1 MB reads fail.
+This is due to the DMA reads being split up into blocks of at most 128kB.
+These reads then fail if the sectorsize is not a divisor of 128kB.
+When reading a full raw audio CD, this leads to roughly 700 error messages
+flying by.
+This is harmless.
--- /dev/null
+++ sbin/recoverdisk/recoverdisk.c
@@ -0,0 +1,295 @@
+/*-
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk at FreeBSD.ORG> wrote this file.  As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ *
+ * $MidnightBSD: src/sbin/recoverdisk/recoverdisk.c,v 1.1 2008/11/11 21:29:37 laffer1 Exp $
+ * $FreeBSD: src/sbin/recoverdisk/recoverdisk.c,v 1.9 2007/06/17 16:53:45 phk Exp $
+ */
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/disk.h>
+#include <sys/stat.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+volatile sig_atomic_t aborting = 0;
+static size_t bigsize = 1024 * 1024;
+static size_t medsize = 64 * 1024;
+static size_t minsize = 512;
+
+struct lump {
+	off_t			start;
+	off_t			len;
+	int			state;
+	TAILQ_ENTRY(lump)	list;
+};
+
+static TAILQ_HEAD(, lump) lumps = TAILQ_HEAD_INITIALIZER(lumps);
+
+static void
+new_lump(off_t start, off_t len, int state)
+{
+	struct lump *lp;
+
+	lp = malloc(sizeof *lp);
+	if (lp == NULL)
+		err(1, "Malloc failed");
+	lp->start = start;
+	lp->len = len;
+	lp->state = state;
+	TAILQ_INSERT_TAIL(&lumps, lp, list);
+}
+
+static struct lump *lp;
+static char *wworklist = NULL;
+static char *rworklist = NULL;
+
+
+#define PRINT_HEADER \
+	printf("%13s %7s %13s %5s %13s %13s %9s\n", \
+		"start", "size", "block-len", "state", "done", "remaining", "% done")
+
+#define PRINT_STATUS(start, i, len, state, d, t) \
+	printf("\r%13jd %7zu %13jd %5d %13jd %13jd %9.5f", \
+		(intmax_t)start, \
+		i,  \
+		(intmax_t)len, \
+		state, \
+		(intmax_t)d, \
+		(intmax_t)(t - d), \
+		100*(double)d/(double)t)
+
+/* Save the worklist if -w was given */
+static void
+save_worklist(void)
+{
+	FILE *file;
+
+	if (wworklist != NULL) {
+		(void)fprintf(stderr, "\nSaving worklist ...");
+		fflush(stderr);
+
+		file = fopen(wworklist, "w");
+		if (file == NULL)
+			err(1, "Error opening file %s", wworklist);
+
+		for (;;) {
+			lp = TAILQ_FIRST(&lumps);
+			if (lp == NULL)
+				break;
+			fprintf(file, "%jd %jd %d\n",
+			    (intmax_t)lp->start, (intmax_t)lp->len, lp->state);
+			TAILQ_REMOVE(&lumps, lp, list);
+		}
+		(void)fprintf(stderr, " done.\n");
+	}
+}
+
+/* Read the worklist if -r was given */
+static off_t
+read_worklist(off_t t)
+{
+	off_t s, l, d;
+	int state, lines;
+	FILE *file;
+
+	(void)fprintf(stderr, "Reading worklist ...");
+	fflush(stderr);
+	file = fopen(rworklist, "r");
+	if (file == NULL)
+		err(1, "Error opening file %s", rworklist);
+
+	lines = 0;
+	d = t;
+	for (;;) {
+		++lines;
+		if (3 != fscanf(file, "%jd %jd %d\n", &s, &l, &state)) {
+			if (!feof(file))
+				err(1, "Error parsing file %s at line %d",
+				    rworklist, lines);
+			else
+				break;
+		}
+		new_lump(s, l, state);
+		d -= l;
+	}
+	(void)fprintf(stderr, " done.\n");
+	/*
+	 * Return the number of bytes already read
+	 * (at least not in worklist).
+	 */
+	return (d);
+}
+
+static void
+usage(void)
+{
+	(void)fprintf(stderr,
+    "usage: recoverdisk [-r worklist] [-w worklist] source-drive [destination]\n");
+	exit(1);
+}
+
+static void
+sighandler(__unused int sig)
+{
+
+	aborting = 1;
+}
+
+int
+main(int argc, char * const argv[])
+{
+	int ch;
+	int fdr, fdw;
+	off_t t, d, start, len;
+	size_t i, j;
+	int error, flags, state;
+	u_char *buf;
+	u_int sectorsize;
+	time_t t1, t2;
+	struct stat sb;
+
+	while ((ch = getopt(argc, argv, "r:w:")) != -1) {
+		switch (ch) {
+		case 'r':
+			rworklist = strdup(optarg);
+			if (rworklist == NULL)
+				err(1, "Cannot allocate enough memory");
+			break;
+		case 'w':
+			wworklist = strdup(optarg);
+			if (wworklist == NULL)
+				err(1, "Cannot allocate enough memory");
+			break;
+		default:
+			usage();
+			/* NOTREACHED */
+		}
+	}
+	argc -= optind;
+	argv += optind;
+
+	if (argc < 1 || argc > 2)
+		usage();
+
+	fdr = open(argv[0], O_RDONLY);
+	if (fdr < 0)
+		err(1, "Cannot open read descriptor %s", argv[0]);
+
+	error = fstat(fdr, &sb);
+	if (error < 0)
+		err(1, "fstat failed");
+	flags = O_WRONLY;
+	if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) {
+		error = ioctl(fdr, DIOCGSECTORSIZE, &sectorsize);
+		if (error < 0)
+			err(1, "DIOCGSECTORSIZE failed");
+
+		/*
+		 * Make medsize roughly 64kB, depending on native sector
+		 * size. bigsize has to be a multiple of medsize.
+		 * For media with 2352 sectors, this will
+		 * result in 2352, 63504, and 1016064 bytes.
+		 */
+		minsize = sectorsize;
+		medsize = (medsize / sectorsize) * sectorsize;
+		bigsize = medsize * 16;
+
+		error = ioctl(fdr, DIOCGMEDIASIZE, &t);
+		if (error < 0)
+			err(1, "DIOCGMEDIASIZE failed");
+	} else {
+		t = sb.st_size;
+		flags |= O_CREAT | O_TRUNC;
+	}
+
+	buf = malloc(bigsize);
+	if (buf == NULL)
+		err(1, "Cannot allocate %jd bytes buffer", (intmax_t)bigsize);
+
+	if (argc > 1) {
+		fdw = open(argv[1], flags, DEFFILEMODE);
+		if (fdw < 0)
+			err(1, "Cannot open write descriptor %s", argv[1]);
+	} else
+		fdw = -1;
+
+	if (rworklist != NULL) {
+		d = read_worklist(t);
+	} else {
+		new_lump(0, t, 0);
+		d = 0;
+	}
+	if (wworklist != NULL)
+		signal(SIGINT, sighandler);
+
+	t1 = 0;
+	start = len = i = state = 0;
+	PRINT_HEADER;
+	for (;;) {
+		lp = TAILQ_FIRST(&lumps);
+		if (lp == NULL)
+			break;
+		while (lp->len > 0 && !aborting) {
+			/* These are only copied for printing stats */
+			start = lp->start;
+			len = lp->len;
+			state = lp->state;
+
+			i = MIN(lp->len, (off_t)bigsize);
+			if (lp->state == 1)
+				i = MIN(lp->len, (off_t)medsize);
+			if (lp->state > 1)
+				i = MIN(lp->len, (off_t)minsize);
+			time(&t2);
+			if (t1 != t2 || lp->len < (off_t)bigsize) {
+				PRINT_STATUS(start, i, len, state, d, t);
+				t1 = t2;
+			}
+			if (i == 0) {
+				errx(1, "BOGUS i %10jd", (intmax_t)i);
+			}
+			fflush(stdout);
+			j = pread(fdr, buf, i, lp->start);
+			if (j == i) {
+				d += i;
+				if (fdw >= 0)
+					j = pwrite(fdw, buf, i, lp->start);
+				else
+					j = i;
+				if (j != i)
+					printf("\nWrite error at %jd/%zu\n",
+					    lp->start, i);
+				lp->start += i;
+				lp->len -= i;
+				continue;
+			}
+			printf("\n%jd %zu failed %d\n", lp->start, i, errno);
+			new_lump(lp->start, i, lp->state + 1);
+			lp->start += i;
+			lp->len -= i;
+		}
+		if (aborting) {
+			save_worklist();
+			return (0);
+		}
+		TAILQ_REMOVE(&lumps, lp, list);
+		free(lp);
+	}
+	PRINT_STATUS(start, i, len, state, d, t);
+	printf("\nCompleted\n");
+	return (0);
+}
--- /dev/null
+++ sbin/recoverdisk/Makefile
@@ -0,0 +1,10 @@
+# $MidnightBSD: src/sbin/recoverdisk/Makefile,v 1.1 2008/11/11 21:29:37 laffer1 Exp $
+# $FreeBSD: src/sbin/recoverdisk/Makefile,v 1.5 2006/05/30 19:10:18 matteo Exp $
+
+PROG=	recoverdisk
+WARNS?=	6
+
+.include <bsd.prog.mk>
+
+test:	${PROG}
+	./${PROG} /dev/ad0


More information about the Midnightbsd-cvs mailing list