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