1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1991-2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _GLOBAL_H 28*7c478bd9Sstevel@tonic-gate #define _GLOBAL_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 33*7c478bd9Sstevel@tonic-gate extern "C" { 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate /* 37*7c478bd9Sstevel@tonic-gate * Definitions for Label types: L_TYPE_SOLORIS is the default Sun label 38*7c478bd9Sstevel@tonic-gate * a.k.a VTOC. L_TYPE_EFI is the EFI label type. 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate #define L_TYPE_SOLARIS 0 41*7c478bd9Sstevel@tonic-gate #define L_TYPE_EFI 1 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #ifndef UINT_MAX64 44*7c478bd9Sstevel@tonic-gate #define UINT_MAX64 0xffffffffffffffff 45*7c478bd9Sstevel@tonic-gate #endif 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate #ifndef UINT_MAX32 48*7c478bd9Sstevel@tonic-gate #define UINT_MAX32 0xffffffff 49*7c478bd9Sstevel@tonic-gate #endif 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate /* 52*7c478bd9Sstevel@tonic-gate * This is the size of the reserved partition. 53*7c478bd9Sstevel@tonic-gate * Valid in case of EFI labels. 54*7c478bd9Sstevel@tonic-gate */ 55*7c478bd9Sstevel@tonic-gate #define EFI_MIN_RESV_SIZE (16 * 1024) 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /* 58*7c478bd9Sstevel@tonic-gate * This file contains global definitions and declarations. It is intended 59*7c478bd9Sstevel@tonic-gate * to be included by everyone. 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate #include <stdio.h> 62*7c478bd9Sstevel@tonic-gate #include <assert.h> 63*7c478bd9Sstevel@tonic-gate #include <memory.h> 64*7c478bd9Sstevel@tonic-gate #include <unistd.h> 65*7c478bd9Sstevel@tonic-gate #include <ctype.h> 66*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 67*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 68*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate #include <sys/dklabel.h> 71*7c478bd9Sstevel@tonic-gate #include <sys/vtoc.h> 72*7c478bd9Sstevel@tonic-gate #include <sys/dkio.h> 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate #include "hardware_structs.h" 75*7c478bd9Sstevel@tonic-gate #include "defect.h" 76*7c478bd9Sstevel@tonic-gate #include "io.h" 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate #include <sys/dktp/fdisk.h> 79*7c478bd9Sstevel@tonic-gate #include <sys/fcntl.h> 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate /* 83*7c478bd9Sstevel@tonic-gate * These declarations are global state variables. 84*7c478bd9Sstevel@tonic-gate */ 85*7c478bd9Sstevel@tonic-gate struct disk_info *disk_list; /* list of found disks */ 86*7c478bd9Sstevel@tonic-gate struct ctlr_info *ctlr_list; /* list of found ctlrs */ 87*7c478bd9Sstevel@tonic-gate char cur_menu; /* current menu level */ 88*7c478bd9Sstevel@tonic-gate char last_menu; /* last menu level */ 89*7c478bd9Sstevel@tonic-gate char option_msg; /* extended message options */ 90*7c478bd9Sstevel@tonic-gate char diag_msg; /* extended diagnostic msgs */ 91*7c478bd9Sstevel@tonic-gate char option_s; /* silent mode option */ 92*7c478bd9Sstevel@tonic-gate char *option_f; /* input redirect option */ 93*7c478bd9Sstevel@tonic-gate char *option_l; /* log file option */ 94*7c478bd9Sstevel@tonic-gate FILE *log_file; /* log file pointer */ 95*7c478bd9Sstevel@tonic-gate char *option_d; /* forced disk option */ 96*7c478bd9Sstevel@tonic-gate char *option_t; /* forced disk type option */ 97*7c478bd9Sstevel@tonic-gate char *option_p; /* forced partition table option */ 98*7c478bd9Sstevel@tonic-gate char *option_x; /* data file redirection option */ 99*7c478bd9Sstevel@tonic-gate FILE *data_file; /* data file pointer */ 100*7c478bd9Sstevel@tonic-gate char *file_name; /* current data file name */ 101*7c478bd9Sstevel@tonic-gate /* for useful error messages */ 102*7c478bd9Sstevel@tonic-gate int expert_mode; /* enable for expert mode */ 103*7c478bd9Sstevel@tonic-gate /* commands */ 104*7c478bd9Sstevel@tonic-gate int need_newline; /* for correctly formatted output */ 105*7c478bd9Sstevel@tonic-gate int dev_expert; /* enable for developer mode */ 106*7c478bd9Sstevel@tonic-gate /* commands */ 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate /* 109*7c478bd9Sstevel@tonic-gate * These declarations are used for quick access to information about 110*7c478bd9Sstevel@tonic-gate * the disk being worked on. 111*7c478bd9Sstevel@tonic-gate */ 112*7c478bd9Sstevel@tonic-gate int cur_file; /* file descriptor for current disk */ 113*7c478bd9Sstevel@tonic-gate int cur_flags; /* flags for current disk */ 114*7c478bd9Sstevel@tonic-gate int cur_label; /* current label type */ 115*7c478bd9Sstevel@tonic-gate struct disk_info *cur_disk; /* current disk */ 116*7c478bd9Sstevel@tonic-gate struct disk_type *cur_dtype; /* current dtype */ 117*7c478bd9Sstevel@tonic-gate struct ctlr_info *cur_ctlr; /* current ctlr */ 118*7c478bd9Sstevel@tonic-gate struct ctlr_type *cur_ctype; /* current ctype */ 119*7c478bd9Sstevel@tonic-gate struct ctlr_ops *cur_ops; /* current ctlr's ops vector */ 120*7c478bd9Sstevel@tonic-gate struct partition_info *cur_parts; /* current disk's partitioning */ 121*7c478bd9Sstevel@tonic-gate struct defect_list cur_list; /* current disk's defect list */ 122*7c478bd9Sstevel@tonic-gate void *cur_buf; /* current disk's I/O buffer */ 123*7c478bd9Sstevel@tonic-gate void *pattern_buf; /* current disk's pattern buffer */ 124*7c478bd9Sstevel@tonic-gate int pcyl; /* # physical cyls */ 125*7c478bd9Sstevel@tonic-gate int ncyl; /* # data cyls */ 126*7c478bd9Sstevel@tonic-gate int acyl; /* # alt cyls */ 127*7c478bd9Sstevel@tonic-gate int nhead; /* # heads */ 128*7c478bd9Sstevel@tonic-gate int phead; /* # physical heads */ 129*7c478bd9Sstevel@tonic-gate int nsect; /* # data sects/track */ 130*7c478bd9Sstevel@tonic-gate int psect; /* # physical sects/track */ 131*7c478bd9Sstevel@tonic-gate int apc; /* # alternates/cyl */ 132*7c478bd9Sstevel@tonic-gate int solaris_offset; /* Solaris offset, this value is zero */ 133*7c478bd9Sstevel@tonic-gate /* for non-fdisk machines. */ 134*7c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16) 135*7c478bd9Sstevel@tonic-gate int bcyl; /* # other cyls */ 136*7c478bd9Sstevel@tonic-gate #endif /* defined(_SUNOS_VTOC_16) */ 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate struct mboot boot_sec; /* fdisk partition info */ 139*7c478bd9Sstevel@tonic-gate int xstart; /* solaris partition start */ 140*7c478bd9Sstevel@tonic-gate char x86_devname[80]; /* saved device name for fdisk */ 141*7c478bd9Sstevel@tonic-gate /* information accesses */ 142*7c478bd9Sstevel@tonic-gate struct mctlr_list *controlp; /* master controller list ptr */ 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /* 146*7c478bd9Sstevel@tonic-gate * These defines are used to manipulate the physical characteristics of 147*7c478bd9Sstevel@tonic-gate * the current disk. 148*7c478bd9Sstevel@tonic-gate */ 149*7c478bd9Sstevel@tonic-gate #define sectors(h) ((h) == nhead - 1 ? nsect - apc : nsect) 150*7c478bd9Sstevel@tonic-gate #define spc() ((int)(nhead * nsect - apc)) 151*7c478bd9Sstevel@tonic-gate #define chs2bn(c, h, s) ((daddr_t)((c) * spc() + (h) * nsect + (s))) 152*7c478bd9Sstevel@tonic-gate #define bn2c(bn) ((bn) / (int)spc()) 153*7c478bd9Sstevel@tonic-gate #define bn2h(bn) (((bn) % (int)spc()) / (int)nsect) 154*7c478bd9Sstevel@tonic-gate #define bn2s(bn) (((bn) % (int)spc()) % (int)nsect) 155*7c478bd9Sstevel@tonic-gate #define datasects() (ncyl * spc()) 156*7c478bd9Sstevel@tonic-gate #define totalsects() ((ncyl + acyl) * spc()) 157*7c478bd9Sstevel@tonic-gate #define physsects() (pcyl * spc()) 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate /* 160*7c478bd9Sstevel@tonic-gate * Macro to convert a device number into a partition number 161*7c478bd9Sstevel@tonic-gate */ 162*7c478bd9Sstevel@tonic-gate #define PARTITION(dev) (minor(dev) & 0x07) 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate /* 165*7c478bd9Sstevel@tonic-gate * These values define flags for the current disk (cur_flags). 166*7c478bd9Sstevel@tonic-gate */ 167*7c478bd9Sstevel@tonic-gate #define DISK_FORMATTED 0x01 /* disk is formatted */ 168*7c478bd9Sstevel@tonic-gate #define LABEL_DIRTY 0x02 /* label has been scribbled */ 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate /* 171*7c478bd9Sstevel@tonic-gate * These flags are for the controller type flags field. 172*7c478bd9Sstevel@tonic-gate */ 173*7c478bd9Sstevel@tonic-gate #define CF_NONE 0x0000 /* NO FLAGS */ 174*7c478bd9Sstevel@tonic-gate #define CF_BLABEL 0x0001 /* backup labels in funny place */ 175*7c478bd9Sstevel@tonic-gate #define CF_DEFECTS 0x0002 /* disk has manuf. defect list */ 176*7c478bd9Sstevel@tonic-gate #define CF_APC 0x0004 /* ctlr uses alternates per cyl */ 177*7c478bd9Sstevel@tonic-gate #define CF_SMD_DEFS 0x0008 /* ctlr does smd defect handling */ 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate #define CF_SCSI 0x0040 /* ctlr is for SCSI disks */ 180*7c478bd9Sstevel@tonic-gate #define CF_EMBEDDED 0x0080 /* ctlr is for embedded SCSI disks */ 181*7c478bd9Sstevel@tonic-gate 182*7c478bd9Sstevel@tonic-gate #define CF_IPI 0x0100 /* ctlr is for IPI disks */ 183*7c478bd9Sstevel@tonic-gate #define CF_WLIST 0x0200 /* ctlt handles working list */ 184*7c478bd9Sstevel@tonic-gate #define CF_NOFORMAT 0x0400 /* Manufacture formatting only */ 185*7c478bd9Sstevel@tonic-gate /* 186*7c478bd9Sstevel@tonic-gate * This flag has been introduced only for SPARC ATA. Which has been approved 187*7c478bd9Sstevel@tonic-gate * at that time with the agreement in the next fix it will be removed and the 188*7c478bd9Sstevel@tonic-gate * format will be revamped with controller Ops structure not to have 189*7c478bd9Sstevel@tonic-gate * any operation to be NULL. As it makes things more modular. 190*7c478bd9Sstevel@tonic-gate * 191*7c478bd9Sstevel@tonic-gate * This flag is also used for PCMCIA pcata driver. 192*7c478bd9Sstevel@tonic-gate * The flag prevents reading or writing a defect list on the disk 193*7c478bd9Sstevel@tonic-gate * testing and console error reporting still work normally. 194*7c478bd9Sstevel@tonic-gate * This is appropriate for the PCMCIA disks which often have MS/DOS filesystems 195*7c478bd9Sstevel@tonic-gate * and have not allocated any space for alternate cylinders to keep 196*7c478bd9Sstevel@tonic-gate * the bab block lists. 197*7c478bd9Sstevel@tonic-gate */ 198*7c478bd9Sstevel@tonic-gate #define CF_NOWLIST 0x0800 /* Ctlr doesnot handle working list */ 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate /* 202*7c478bd9Sstevel@tonic-gate * Do not require confirmation to extract defect lists on SCSI 203*7c478bd9Sstevel@tonic-gate * and IPI drives, since this operation is instantaneous 204*7c478bd9Sstevel@tonic-gate */ 205*7c478bd9Sstevel@tonic-gate #define CF_CONFIRM (CF_SCSI|CF_IPI) 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate /* 208*7c478bd9Sstevel@tonic-gate * Macros to make life easier 209*7c478bd9Sstevel@tonic-gate */ 210*7c478bd9Sstevel@tonic-gate #define SMD (cur_ctype->ctype_flags & CF_SMD_DEFS) 211*7c478bd9Sstevel@tonic-gate #define SCSI (cur_ctype->ctype_flags & CF_SCSI) 212*7c478bd9Sstevel@tonic-gate #define EMBEDDED_SCSI ((cur_ctype->ctype_flags & (CF_SCSI|CF_EMBEDDED)) == \ 213*7c478bd9Sstevel@tonic-gate (CF_SCSI|CF_EMBEDDED)) 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate /* 216*7c478bd9Sstevel@tonic-gate * These flags are for the disk type flags field. 217*7c478bd9Sstevel@tonic-gate */ 218*7c478bd9Sstevel@tonic-gate #define DT_NEED_SPEFS 0x01 /* specifics fields are uninitialized */ 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate /* 221*7c478bd9Sstevel@tonic-gate * These defines are used to access the ctlr specific 222*7c478bd9Sstevel@tonic-gate * disk type fields (based on ctlr flags). 223*7c478bd9Sstevel@tonic-gate */ 224*7c478bd9Sstevel@tonic-gate #define dtype_bps dtype_specifics[0] /* bytes/sector */ 225*7c478bd9Sstevel@tonic-gate #define dtype_dr_type dtype_specifics[1] /* drive type */ 226*7c478bd9Sstevel@tonic-gate #define dtype_dr_type_data dtype_specifics[2] /* drive type in data file */ 227*7c478bd9Sstevel@tonic-gate 228*7c478bd9Sstevel@tonic-gate /* 229*7c478bd9Sstevel@tonic-gate * These flags are for the disk info flags field. 230*7c478bd9Sstevel@tonic-gate */ 231*7c478bd9Sstevel@tonic-gate #define DSK_LABEL 0x01 /* disk is currently labelled */ 232*7c478bd9Sstevel@tonic-gate #define DSK_LABEL_DIRTY 0x02 /* disk auto-sensed, but not */ 233*7c478bd9Sstevel@tonic-gate /* labeled yet. */ 234*7c478bd9Sstevel@tonic-gate #define DSK_AUTO_CONFIG 0x04 /* disk was auto-configured */ 235*7c478bd9Sstevel@tonic-gate #define DSK_RESERVED 0x08 /* disk is reserved by other host */ 236*7c478bd9Sstevel@tonic-gate #define DSK_UNAVAILABLE 0x10 /* disk not available, could be */ 237*7c478bd9Sstevel@tonic-gate /* currently formatting */ 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate /* 240*7c478bd9Sstevel@tonic-gate * These flags are used to control disk command execution. 241*7c478bd9Sstevel@tonic-gate */ 242*7c478bd9Sstevel@tonic-gate #define F_NORMAL 0x00 /* normal operation */ 243*7c478bd9Sstevel@tonic-gate #define F_SILENT 0x01 /* no error msgs at all */ 244*7c478bd9Sstevel@tonic-gate #define F_ALLERRS 0x02 /* return any error, not just fatal */ 245*7c478bd9Sstevel@tonic-gate #define F_RQENABLE 0x04 /* no error msgs at all */ 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate /* 248*7c478bd9Sstevel@tonic-gate * Directional parameter for the op_rdwr controller op. 249*7c478bd9Sstevel@tonic-gate */ 250*7c478bd9Sstevel@tonic-gate #define DIR_READ 0 251*7c478bd9Sstevel@tonic-gate #define DIR_WRITE 1 252*7c478bd9Sstevel@tonic-gate 253*7c478bd9Sstevel@tonic-gate /* 254*7c478bd9Sstevel@tonic-gate * These defines are the mode parameter for the checksum routines. 255*7c478bd9Sstevel@tonic-gate */ 256*7c478bd9Sstevel@tonic-gate #define CK_CHECKSUM 0 /* check checksum */ 257*7c478bd9Sstevel@tonic-gate #define CK_MAKESUM 1 /* generate checksum */ 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate /* 260*7c478bd9Sstevel@tonic-gate * This is the base character for partition identifiers 261*7c478bd9Sstevel@tonic-gate */ 262*7c478bd9Sstevel@tonic-gate #define PARTITION_BASE '0' 263*7c478bd9Sstevel@tonic-gate 264*7c478bd9Sstevel@tonic-gate /* 265*7c478bd9Sstevel@tonic-gate * Base pathname for devfs names to be stripped from physical name. 266*7c478bd9Sstevel@tonic-gate */ 267*7c478bd9Sstevel@tonic-gate #define DEVFS_PREFIX "/devices" 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate /* 270*7c478bd9Sstevel@tonic-gate * Function prototypes ... Both for ANSI and non-ANSI C compilers 271*7c478bd9Sstevel@tonic-gate */ 272*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gate int copy_solaris_part(struct ipart *); 275*7c478bd9Sstevel@tonic-gate int good_fdisk(void); 276*7c478bd9Sstevel@tonic-gate int fdisk_physical_name(char *); 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate #else /* __STDC__ */ 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate int copy_solaris_part(); 281*7c478bd9Sstevel@tonic-gate int good_fdisk(); 282*7c478bd9Sstevel@tonic-gate int fdisk_physical_name(); 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 285*7c478bd9Sstevel@tonic-gate 286*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate #endif 289*7c478bd9Sstevel@tonic-gate 290*7c478bd9Sstevel@tonic-gate #endif /* _GLOBAL_H */ 291