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