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