1 /* $NetBSD: dkscan_util.c,v 1.1 2007/03/01 22:01:30 martin Exp $ */
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann <martin@NetBSD.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/param.h>
41 #include <sys/disklabel.h>
43 #include "dkscan_util.h"
45 int verbose
= 0; /* are we verbose? */
46 int no_action
= 0; /* don't do anything, just print info */
47 int disk_fd
= -1; /* file descriptor for disk access */
51 dkcksum(struct disklabel
*lp
)
53 return dkcksum_sized(lp
, lp
->d_npartitions
);
57 dkcksum_sized(struct disklabel
*lp
, size_t npartitions
)
62 start
= (u_short
*)lp
;
63 end
= (u_short
*)&lp
->d_partitions
[npartitions
];
70 dkwedge_read(struct disk
*pdk
, struct vnode
*vp
, daddr_t blkno
,
71 void *tbuf
, size_t len
)
73 if (pread(disk_fd
, tbuf
, len
, blkno
* BLOCK_SIZE
) < 0)
79 dkwedge_add(struct dkwedge_info
*dkw
)
81 printf("wedge \"%s\" type \"%s\" start %" PRIu64
" size %" PRIu64
,
82 dkw
->dkw_wname
, dkw
->dkw_ptype
, dkw
->dkw_offset
, dkw
->dkw_size
);
89 if (ioctl(disk_fd
, DIOCAWEDGE
, dkw
) == -1)
92 printf(": %s\n", dkw
->dkw_devname
);
97 aprint_error(const char *format
, ...)
101 va_start(ap
, format
);
102 vfprintf(stderr
, format
, ap
);
107 aprint_verbose(const char *format
, ...)
111 if (!verbose
) return;
113 va_start(ap
, format
);
114 vfprintf(stdout
, format
, ap
);