1 /* $NetBSD: pdinfo.c,v 1.5 2014/01/22 16:32:09 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 2004 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 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. 18 * 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. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: pdinfo.c,v 1.5 2014/01/22 16:32:09 christos Exp $"); 34 35 #include <sys/types.h> 36 #include <sys/systm.h> 37 38 #ifndef _KERNEL 39 #include "local.h" 40 #endif 41 42 #ifdef PDINFO_DEBUG 43 #define DPRINTF(fmt, args...) printf(fmt, ##args) 44 #else 45 #define DPRINTF(arg...) ((void)0) 46 #endif 47 48 #include <machine/sector.h> 49 #include <machine/pdinfo.h> 50 51 bool 52 pdinfo_sector(void *rwops, struct pdinfo_sector *pdinfo) 53 { 54 55 if (!sector_read(rwops, (void *)pdinfo, PDINFO_SECTOR)) 56 return false; 57 58 if (!pdinfo_sanity(pdinfo)) 59 return false; 60 61 return true; 62 } 63 64 bool 65 pdinfo_valid(const struct pdinfo_sector *disk) 66 { 67 68 return disk->magic == PDINFO_MAGIC; 69 } 70 71 bool 72 pdinfo_sanity(const struct pdinfo_sector *disk) 73 { 74 75 if (!pdinfo_valid(disk)) { 76 DPRINTF("no physical disk info.\n"); 77 return false; 78 } 79 80 #ifdef PDINFO_DEBUG 81 const struct disk_geometory *geom = &disk->geometory; 82 const struct disk_ux *ux = &disk->ux; 83 #endif 84 DPRINTF("physical disk sector size %dbyte\n", sizeof *disk); 85 DPRINTF("[disk]\n"); 86 DPRINTF("drive_id = %#x\n", disk->drive_id); 87 DPRINTF("magic = %#x\n", disk->magic); 88 DPRINTF("version = %d\n", disk->version); 89 DPRINTF("serial # %s\n", disk->device_serial_number); 90 #define _(x) DPRINTF(#x " = %d\n", geom->x); 91 _(cylinders_per_drive); 92 _(tracks_per_cylinder); 93 _(sectors_per_track); 94 _(bytes_per_sector); 95 #undef _ 96 DPRINTF("logical_sector = %d\n", disk->logical_sector); 97 #define _(x) DPRINTF(#x " = %d\n", ux->x); 98 _(errorlog_sector); 99 _(errorlog_size_byte); 100 _(mfg_sector); 101 _(mfg_size_byte); 102 _(defect_sector); 103 _(defect_size_byte); 104 _(n_relocation_area); 105 _(relocation_area_sector); 106 _(relocation_area_size_byte); 107 _(next_relocation_area); 108 _(diag_sector); 109 _(diag_size); 110 _(gap_size); 111 #undef _ 112 /* undocumented region */ 113 { 114 int i, j; 115 DPRINTF("--reserved--\n"); 116 for (i = 0, j = 1; i < 104; i++, j++) { 117 DPRINTF("[%3d]%8x ", i, disk->device_depend[i]); 118 if (j == 8) { 119 DPRINTF("\n"); 120 j = 0; 121 } 122 } 123 } 124 125 return true; 126 } 127