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