17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*052b6e8aSbg159949 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _GLOBAL_H 287c478bd9Sstevel@tonic-gate #define _GLOBAL_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 337c478bd9Sstevel@tonic-gate extern "C" { 347c478bd9Sstevel@tonic-gate #endif 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * Definitions for Label types: L_TYPE_SOLORIS is the default Sun label 387c478bd9Sstevel@tonic-gate * a.k.a VTOC. L_TYPE_EFI is the EFI label type. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate #define L_TYPE_SOLARIS 0 417c478bd9Sstevel@tonic-gate #define L_TYPE_EFI 1 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #ifndef UINT_MAX64 44*052b6e8aSbg159949 #define UINT_MAX64 0xffffffffffffffffULL 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #ifndef UINT_MAX32 487c478bd9Sstevel@tonic-gate #define UINT_MAX32 0xffffffff 497c478bd9Sstevel@tonic-gate #endif 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate /* 527c478bd9Sstevel@tonic-gate * This is the size of the reserved partition. 537c478bd9Sstevel@tonic-gate * Valid in case of EFI labels. 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate #define EFI_MIN_RESV_SIZE (16 * 1024) 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate /* 587c478bd9Sstevel@tonic-gate * This file contains global definitions and declarations. It is intended 597c478bd9Sstevel@tonic-gate * to be included by everyone. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate #include <stdio.h> 627c478bd9Sstevel@tonic-gate #include <assert.h> 637c478bd9Sstevel@tonic-gate #include <memory.h> 647c478bd9Sstevel@tonic-gate #include <unistd.h> 657c478bd9Sstevel@tonic-gate #include <ctype.h> 667c478bd9Sstevel@tonic-gate #include <sys/types.h> 677c478bd9Sstevel@tonic-gate #include <sys/param.h> 687c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #include <sys/dklabel.h> 717c478bd9Sstevel@tonic-gate #include <sys/vtoc.h> 727c478bd9Sstevel@tonic-gate #include <sys/dkio.h> 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate #include "hardware_structs.h" 757c478bd9Sstevel@tonic-gate #include "defect.h" 767c478bd9Sstevel@tonic-gate #include "io.h" 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate #include <sys/dktp/fdisk.h> 797c478bd9Sstevel@tonic-gate #include <sys/fcntl.h> 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * These declarations are global state variables. 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate struct disk_info *disk_list; /* list of found disks */ 867c478bd9Sstevel@tonic-gate struct ctlr_info *ctlr_list; /* list of found ctlrs */ 877c478bd9Sstevel@tonic-gate char cur_menu; /* current menu level */ 887c478bd9Sstevel@tonic-gate char last_menu; /* last menu level */ 897c478bd9Sstevel@tonic-gate char option_msg; /* extended message options */ 907c478bd9Sstevel@tonic-gate char diag_msg; /* extended diagnostic msgs */ 917c478bd9Sstevel@tonic-gate char option_s; /* silent mode option */ 927c478bd9Sstevel@tonic-gate char *option_f; /* input redirect option */ 937c478bd9Sstevel@tonic-gate char *option_l; /* log file option */ 947c478bd9Sstevel@tonic-gate FILE *log_file; /* log file pointer */ 957c478bd9Sstevel@tonic-gate char *option_d; /* forced disk option */ 967c478bd9Sstevel@tonic-gate char *option_t; /* forced disk type option */ 977c478bd9Sstevel@tonic-gate char *option_p; /* forced partition table option */ 987c478bd9Sstevel@tonic-gate char *option_x; /* data file redirection option */ 997c478bd9Sstevel@tonic-gate FILE *data_file; /* data file pointer */ 1007c478bd9Sstevel@tonic-gate char *file_name; /* current data file name */ 1017c478bd9Sstevel@tonic-gate /* for useful error messages */ 1027c478bd9Sstevel@tonic-gate int expert_mode; /* enable for expert mode */ 1037c478bd9Sstevel@tonic-gate /* commands */ 1047c478bd9Sstevel@tonic-gate int need_newline; /* for correctly formatted output */ 1057c478bd9Sstevel@tonic-gate int dev_expert; /* enable for developer mode */ 1067c478bd9Sstevel@tonic-gate /* commands */ 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate /* 1097c478bd9Sstevel@tonic-gate * These declarations are used for quick access to information about 1107c478bd9Sstevel@tonic-gate * the disk being worked on. 1117c478bd9Sstevel@tonic-gate */ 1127c478bd9Sstevel@tonic-gate int cur_file; /* file descriptor for current disk */ 1137c478bd9Sstevel@tonic-gate int cur_flags; /* flags for current disk */ 1147c478bd9Sstevel@tonic-gate int cur_label; /* current label type */ 1157c478bd9Sstevel@tonic-gate struct disk_info *cur_disk; /* current disk */ 1167c478bd9Sstevel@tonic-gate struct disk_type *cur_dtype; /* current dtype */ 1177c478bd9Sstevel@tonic-gate struct ctlr_info *cur_ctlr; /* current ctlr */ 1187c478bd9Sstevel@tonic-gate struct ctlr_type *cur_ctype; /* current ctype */ 1197c478bd9Sstevel@tonic-gate struct ctlr_ops *cur_ops; /* current ctlr's ops vector */ 1207c478bd9Sstevel@tonic-gate struct partition_info *cur_parts; /* current disk's partitioning */ 1217c478bd9Sstevel@tonic-gate struct defect_list cur_list; /* current disk's defect list */ 1227c478bd9Sstevel@tonic-gate void *cur_buf; /* current disk's I/O buffer */ 1237c478bd9Sstevel@tonic-gate void *pattern_buf; /* current disk's pattern buffer */ 1247c478bd9Sstevel@tonic-gate int pcyl; /* # physical cyls */ 1257c478bd9Sstevel@tonic-gate int ncyl; /* # data cyls */ 1267c478bd9Sstevel@tonic-gate int acyl; /* # alt cyls */ 1277c478bd9Sstevel@tonic-gate int nhead; /* # heads */ 1287c478bd9Sstevel@tonic-gate int phead; /* # physical heads */ 1297c478bd9Sstevel@tonic-gate int nsect; /* # data sects/track */ 1307c478bd9Sstevel@tonic-gate int psect; /* # physical sects/track */ 1317c478bd9Sstevel@tonic-gate int apc; /* # alternates/cyl */ 1327c478bd9Sstevel@tonic-gate int solaris_offset; /* Solaris offset, this value is zero */ 1337c478bd9Sstevel@tonic-gate /* for non-fdisk machines. */ 1347c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16) 1357c478bd9Sstevel@tonic-gate int bcyl; /* # other cyls */ 1367c478bd9Sstevel@tonic-gate #endif /* defined(_SUNOS_VTOC_16) */ 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate struct mboot boot_sec; /* fdisk partition info */ 1397c478bd9Sstevel@tonic-gate int xstart; /* solaris partition start */ 1407c478bd9Sstevel@tonic-gate char x86_devname[80]; /* saved device name for fdisk */ 1417c478bd9Sstevel@tonic-gate /* information accesses */ 1427c478bd9Sstevel@tonic-gate struct mctlr_list *controlp; /* master controller list ptr */ 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * These defines are used to manipulate the physical characteristics of 1477c478bd9Sstevel@tonic-gate * the current disk. 1487c478bd9Sstevel@tonic-gate */ 1497c478bd9Sstevel@tonic-gate #define sectors(h) ((h) == nhead - 1 ? nsect - apc : nsect) 1507c478bd9Sstevel@tonic-gate #define spc() ((int)(nhead * nsect - apc)) 1517c478bd9Sstevel@tonic-gate #define chs2bn(c, h, s) ((daddr_t)((c) * spc() + (h) * nsect + (s))) 1527c478bd9Sstevel@tonic-gate #define bn2c(bn) ((bn) / (int)spc()) 1537c478bd9Sstevel@tonic-gate #define bn2h(bn) (((bn) % (int)spc()) / (int)nsect) 1547c478bd9Sstevel@tonic-gate #define bn2s(bn) (((bn) % (int)spc()) % (int)nsect) 1557c478bd9Sstevel@tonic-gate #define datasects() (ncyl * spc()) 1567c478bd9Sstevel@tonic-gate #define totalsects() ((ncyl + acyl) * spc()) 1577c478bd9Sstevel@tonic-gate #define physsects() (pcyl * spc()) 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* 1607c478bd9Sstevel@tonic-gate * Macro to convert a device number into a partition number 1617c478bd9Sstevel@tonic-gate */ 1627c478bd9Sstevel@tonic-gate #define PARTITION(dev) (minor(dev) & 0x07) 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* 1657c478bd9Sstevel@tonic-gate * These values define flags for the current disk (cur_flags). 1667c478bd9Sstevel@tonic-gate */ 1677c478bd9Sstevel@tonic-gate #define DISK_FORMATTED 0x01 /* disk is formatted */ 1687c478bd9Sstevel@tonic-gate #define LABEL_DIRTY 0x02 /* label has been scribbled */ 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * These flags are for the controller type flags field. 1727c478bd9Sstevel@tonic-gate */ 1737c478bd9Sstevel@tonic-gate #define CF_NONE 0x0000 /* NO FLAGS */ 1747c478bd9Sstevel@tonic-gate #define CF_BLABEL 0x0001 /* backup labels in funny place */ 1757c478bd9Sstevel@tonic-gate #define CF_DEFECTS 0x0002 /* disk has manuf. defect list */ 1767c478bd9Sstevel@tonic-gate #define CF_APC 0x0004 /* ctlr uses alternates per cyl */ 1777c478bd9Sstevel@tonic-gate #define CF_SMD_DEFS 0x0008 /* ctlr does smd defect handling */ 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate #define CF_SCSI 0x0040 /* ctlr is for SCSI disks */ 1807c478bd9Sstevel@tonic-gate #define CF_EMBEDDED 0x0080 /* ctlr is for embedded SCSI disks */ 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate #define CF_IPI 0x0100 /* ctlr is for IPI disks */ 1837c478bd9Sstevel@tonic-gate #define CF_WLIST 0x0200 /* ctlt handles working list */ 1847c478bd9Sstevel@tonic-gate #define CF_NOFORMAT 0x0400 /* Manufacture formatting only */ 1857c478bd9Sstevel@tonic-gate /* 1867c478bd9Sstevel@tonic-gate * This flag has been introduced only for SPARC ATA. Which has been approved 1877c478bd9Sstevel@tonic-gate * at that time with the agreement in the next fix it will be removed and the 1887c478bd9Sstevel@tonic-gate * format will be revamped with controller Ops structure not to have 1897c478bd9Sstevel@tonic-gate * any operation to be NULL. As it makes things more modular. 1907c478bd9Sstevel@tonic-gate * 1917c478bd9Sstevel@tonic-gate * This flag is also used for PCMCIA pcata driver. 1927c478bd9Sstevel@tonic-gate * The flag prevents reading or writing a defect list on the disk 1937c478bd9Sstevel@tonic-gate * testing and console error reporting still work normally. 1947c478bd9Sstevel@tonic-gate * This is appropriate for the PCMCIA disks which often have MS/DOS filesystems 1957c478bd9Sstevel@tonic-gate * and have not allocated any space for alternate cylinders to keep 1967c478bd9Sstevel@tonic-gate * the bab block lists. 1977c478bd9Sstevel@tonic-gate */ 1987c478bd9Sstevel@tonic-gate #define CF_NOWLIST 0x0800 /* Ctlr doesnot handle working list */ 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate /* 2027c478bd9Sstevel@tonic-gate * Do not require confirmation to extract defect lists on SCSI 2037c478bd9Sstevel@tonic-gate * and IPI drives, since this operation is instantaneous 2047c478bd9Sstevel@tonic-gate */ 2057c478bd9Sstevel@tonic-gate #define CF_CONFIRM (CF_SCSI|CF_IPI) 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate /* 2087c478bd9Sstevel@tonic-gate * Macros to make life easier 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate #define SMD (cur_ctype->ctype_flags & CF_SMD_DEFS) 2117c478bd9Sstevel@tonic-gate #define SCSI (cur_ctype->ctype_flags & CF_SCSI) 2127c478bd9Sstevel@tonic-gate #define EMBEDDED_SCSI ((cur_ctype->ctype_flags & (CF_SCSI|CF_EMBEDDED)) == \ 2137c478bd9Sstevel@tonic-gate (CF_SCSI|CF_EMBEDDED)) 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate /* 2167c478bd9Sstevel@tonic-gate * These flags are for the disk type flags field. 2177c478bd9Sstevel@tonic-gate */ 2187c478bd9Sstevel@tonic-gate #define DT_NEED_SPEFS 0x01 /* specifics fields are uninitialized */ 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate /* 2217c478bd9Sstevel@tonic-gate * These defines are used to access the ctlr specific 2227c478bd9Sstevel@tonic-gate * disk type fields (based on ctlr flags). 2237c478bd9Sstevel@tonic-gate */ 2247c478bd9Sstevel@tonic-gate #define dtype_bps dtype_specifics[0] /* bytes/sector */ 2257c478bd9Sstevel@tonic-gate #define dtype_dr_type dtype_specifics[1] /* drive type */ 2267c478bd9Sstevel@tonic-gate #define dtype_dr_type_data dtype_specifics[2] /* drive type in data file */ 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate /* 2297c478bd9Sstevel@tonic-gate * These flags are for the disk info flags field. 2307c478bd9Sstevel@tonic-gate */ 2317c478bd9Sstevel@tonic-gate #define DSK_LABEL 0x01 /* disk is currently labelled */ 2327c478bd9Sstevel@tonic-gate #define DSK_LABEL_DIRTY 0x02 /* disk auto-sensed, but not */ 2337c478bd9Sstevel@tonic-gate /* labeled yet. */ 2347c478bd9Sstevel@tonic-gate #define DSK_AUTO_CONFIG 0x04 /* disk was auto-configured */ 2357c478bd9Sstevel@tonic-gate #define DSK_RESERVED 0x08 /* disk is reserved by other host */ 2367c478bd9Sstevel@tonic-gate #define DSK_UNAVAILABLE 0x10 /* disk not available, could be */ 2377c478bd9Sstevel@tonic-gate /* currently formatting */ 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate /* 2407c478bd9Sstevel@tonic-gate * These flags are used to control disk command execution. 2417c478bd9Sstevel@tonic-gate */ 2427c478bd9Sstevel@tonic-gate #define F_NORMAL 0x00 /* normal operation */ 2437c478bd9Sstevel@tonic-gate #define F_SILENT 0x01 /* no error msgs at all */ 2447c478bd9Sstevel@tonic-gate #define F_ALLERRS 0x02 /* return any error, not just fatal */ 2457c478bd9Sstevel@tonic-gate #define F_RQENABLE 0x04 /* no error msgs at all */ 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* 2487c478bd9Sstevel@tonic-gate * Directional parameter for the op_rdwr controller op. 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate #define DIR_READ 0 2517c478bd9Sstevel@tonic-gate #define DIR_WRITE 1 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate /* 2547c478bd9Sstevel@tonic-gate * These defines are the mode parameter for the checksum routines. 2557c478bd9Sstevel@tonic-gate */ 2567c478bd9Sstevel@tonic-gate #define CK_CHECKSUM 0 /* check checksum */ 2577c478bd9Sstevel@tonic-gate #define CK_MAKESUM 1 /* generate checksum */ 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate /* 2607c478bd9Sstevel@tonic-gate * This is the base character for partition identifiers 2617c478bd9Sstevel@tonic-gate */ 2627c478bd9Sstevel@tonic-gate #define PARTITION_BASE '0' 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* 2657c478bd9Sstevel@tonic-gate * Base pathname for devfs names to be stripped from physical name. 2667c478bd9Sstevel@tonic-gate */ 2677c478bd9Sstevel@tonic-gate #define DEVFS_PREFIX "/devices" 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate /* 2707c478bd9Sstevel@tonic-gate * Function prototypes ... Both for ANSI and non-ANSI C compilers 2717c478bd9Sstevel@tonic-gate */ 2727c478bd9Sstevel@tonic-gate #ifdef __STDC__ 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate int copy_solaris_part(struct ipart *); 2757c478bd9Sstevel@tonic-gate int good_fdisk(void); 2767c478bd9Sstevel@tonic-gate int fdisk_physical_name(char *); 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate #else /* __STDC__ */ 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate int copy_solaris_part(); 2817c478bd9Sstevel@tonic-gate int good_fdisk(); 2827c478bd9Sstevel@tonic-gate int fdisk_physical_name(); 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate #endif 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate #endif /* _GLOBAL_H */ 291