1 /* 2 3 File: bsd.h 4 5 Copyright (C) 1998-2004,2006,2008 Christophe GRENIER <grenier@cgsecurity.org> 6 7 This software is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License along 18 with this program; if not, write the Free Software Foundation, Inc., 51 19 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 21 */ 22 /* Come mainly from sys/disklabel.h and disktab.h */ 23 24 #ifndef _BSD_H 25 #define _BSD_H 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 /* BSD_DISKLABEL_SIZE is 276 */ 30 #define BSD_DISKLABEL_SIZE 512 31 #define STANDALONE 32 33 #define BBSIZE 8192 /* size of boot area, with label */ 34 35 #ifdef __i386__ 36 #define LABELSECTOR 1 /* sector containing label */ 37 #define LABELOFFSET 0 /* offset of label in sector */ 38 #endif 39 40 #ifndef LABELSECTOR 41 #define LABELSECTOR 0 /* sector containing label */ 42 #endif 43 44 #ifndef LABELOFFSET 45 #define LABELOFFSET 64 /* offset of label in sector */ 46 #endif 47 48 #define DISKMAGIC ((uint32_t)0x82564557) /* The disk magic number */ 49 50 #define LABEL_PART 2 /* partition containing label */ 51 #define RAW_PART 2 /* partition containing whole disk */ 52 #define SWAP_PART 1 /* partition normally containing swap */ 53 54 struct disklabel { 55 uint32_t d_magic; /* the magic number */ 56 uint16_t d_type; /* drive type */ 57 uint16_t d_subtype; /* controller/d_type specific */ 58 char d_typename[16]; /* type name, e.g. "eagle" */ 59 60 /* 61 * d_packname contains the pack identifier and is returned when 62 * the disklabel is read off the disk or in-core copy. 63 * d_boot0 and d_boot1 are the (optional) names of the 64 * primary (block 0) and secondary (block 1-15) bootstraps 65 * as found in /usr/mdec. These are returned when using 66 * getdiskbyname(3) to retrieve the values from /etc/disktab. 67 */ 68 #if defined(KERNEL) || defined(STANDALONE) 69 char d_packname[16]; /* pack identifier */ 70 #else 71 union { 72 char un_d_packname[16]; /* pack identifier */ 73 struct { 74 char *un_d_boot0; /* primary bootstrap name */ 75 char *un_d_boot1; /* secondary bootstrap name */ 76 } un_b; 77 } d_un; 78 #define d_packname d_un.un_d_packname 79 #define d_boot0 d_un.un_b.un_d_boot0 80 #define d_boot1 d_un.un_b.un_d_boot1 81 #endif /* ! KERNEL or STANDALONE */ 82 83 /* disk geometry: */ 84 uint32_t d_secsize; /* # of bytes per sector */ 85 uint32_t d_nsectors; /* # of data sectors per track */ 86 uint32_t d_ntracks; /* # of tracks per cylinder */ 87 uint32_t d_ncylinders; /* # of data cylinders per unit */ 88 uint32_t d_secpercyl; /* # of data sectors per cylinder */ 89 uint32_t d_secperunit; /* # of data sectors per unit */ 90 91 /* 92 * Spares (bad sector replacements) below are not counted in 93 * d_nsectors or d_secpercyl. Spare sectors are assumed to 94 * be physical sectors which occupy space at the end of each 95 * track and/or cylinder. 96 */ 97 uint16_t d_sparespertrack; /* # of spare sectors per track */ 98 uint16_t d_sparespercyl; /* # of spare sectors per cylinder */ 99 /* 100 * Alternate cylinders include maintenance, replacement, configuration 101 * description areas, etc. 102 */ 103 uint32_t d_acylinders; /* # of alt. cylinders per unit */ 104 105 /* hardware characteristics: */ 106 /* 107 * d_interleave, d_trackskew and d_cylskew describe perturbations 108 * in the media format used to compensate for a slow controller. 109 * Interleave is physical sector interleave, set up by the 110 * formatter or controller when formatting. When interleaving is 111 * in use, logically adjacent sectors are not physically 112 * contiguous, but instead are separated by some number of 113 * sectors. It is specified as the ratio of physical sectors 114 * traversed per logical sector. Thus an interleave of 1:1 115 * implies contiguous layout, while 2:1 implies that logical 116 * sector 0 is separated by one sector from logical sector 1. 117 * d_trackskew is the offset of sector 0 on track N relative to 118 * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew 119 * is the offset of sector 0 on cylinder N relative to sector 0 120 * on cylinder N-1. 121 */ 122 uint16_t d_rpm; /* rotational speed */ 123 uint16_t d_interleave; /* hardware sector interleave */ 124 uint16_t d_trackskew; /* sector 0 skew, per track */ 125 uint16_t d_cylskew; /* sector 0 skew, per cylinder */ 126 uint32_t d_headswitch; /* head switch time, usec */ 127 uint32_t d_trkseek; /* track-to-track seek, usec */ 128 uint32_t d_flags; /* generic flags */ 129 #define NDDATA 5 130 uint32_t d_drivedata[NDDATA]; /* drive-type specific information */ 131 #define NSPARE 5 132 uint32_t d_spare[NSPARE]; /* reserved for future use */ 133 uint32_t d_magic2; /* the magic number (again) */ 134 uint16_t d_checksum; /* xor of data incl. partitions */ 135 136 /* filesystem and partition information: */ 137 uint16_t d_npartitions; /* number of partitions in following */ 138 uint32_t d_bbsize; /* size of boot area at sn0, bytes */ 139 uint32_t d_sbsize; /* max size of fs superblock, bytes */ 140 struct partition { /* the partition table */ 141 uint32_t p_size; /* number of sectors in partition */ 142 uint32_t p_offset; /* starting sector */ 143 uint32_t p_fsize; /* filesystem basic fragment size */ 144 uint8_t p_fstype; /* filesystem type, see below */ 145 uint8_t p_frag; /* filesystem fragments per block */ 146 union { 147 uint16_t cpg; /* UFS: FS cylinders per group */ 148 uint16_t sgs; /* LFS: FS segment shift */ 149 } __partition_u1; 150 #define p_cpg __partition_u1.cpg 151 #define p_sgs __partition_u1.sgs 152 } d_partitions[OPENBSD_MAXPARTITIONS]; /* actually may be more */ 153 }; 154 #define TST_FS_UNUSED 0 /* unused */ 155 #define TST_FS_SWAP 1 /* swap */ 156 #define TST_FS_V6 2 /* Sixth Edition */ 157 #define TST_FS_V7 3 /* Seventh Edition */ 158 #define TST_FS_SYSV 4 /* System V */ 159 #define TST_FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ 160 #define TST_FS_V8 6 /* Eighth Edition, 4K blocks */ 161 #define TST_FS_BSDFFS 7 /* 4.2BSD fast filesystem */ 162 #define TST_FS_MSDOS 8 /* MSDOS filesystem */ 163 #define TST_FS_BSDLFS 9 /* 4.4BSD log-structured filesystem */ 164 #define TST_FS_OTHER 10 /* in use, but unknown/unsupported */ 165 #define TST_FS_HPFS 11 /* OS/2 high-performance filesystem */ 166 #define TST_FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ 167 #define TST_FS_BOOT 13 /* partition contains bootstrap */ 168 #define TST_FS_VINUM 14 /* Vinum drive */ 169 #define TST_FS_RAID 15 /* RAIDFrame drive */ 170 #define TST_FS_JFS2 21 /* IBM JFS2 */ 171 int check_BSD(disk_t *disk_car,partition_t *partition,const int verbose,const unsigned int max_partitions); 172 int recover_BSD(disk_t *disk_car, const struct disklabel*bsd_header,partition_t *partition,const int verbose, const int dump_ind); 173 #ifdef __cplusplus 174 } /* closing brace for extern "C" */ 175 #endif 176 #endif 177