xref: /illumos-gate/usr/src/cmd/rmformat/rmformat.h (revision 9174bfaa08ca3aa4c0a12e840c4bd4f2570237a0)
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	_RMFORMAT_H
28 #define	_RMFORMAT_H
29 
30 /*
31  * This file contents the definitions for rmformat utility
32  */
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #include <stdio.h>
39 #include <strings.h>
40 #include <sys/stat.h>
41 #include <stdlib.h>
42 #include <errno.h>
43 #include <sys/param.h>
44 #include <unistd.h>
45 #include <limits.h>
46 #include <volmgt.h>
47 #include <sys/vtoc.h>
48 #include <locale.h>
49 #include <libintl.h>
50 #include <dirent.h>
51 #include <sys/dkio.h>
52 #include <sys/dktp/fdisk.h>
53 #include <sys/smedia.h>
54 #include <sys/efi_partition.h>
55 
56 #ifdef	DEBUG
57 #define	DPRINTF(str)			(void) printf(str)
58 #define	DPRINTF1(str, a)		(void) printf(str, a)
59 #define	DPRINTF2(str, a, b)		(void) printf(str, a, b)
60 #define	DPRINTF3(str, a, b, c)		(void) printf(str, a, b, c)
61 #define	DPRINTF4(str, a, b, c, d)	(void) printf(str, a, b, c, d)
62 #else
63 #define	DPRINTF(str)
64 #define	DPRINTF1(str, a)
65 #define	DPRINTF2(str, a, b)
66 #define	DPRINTF3(str, a, b, c)
67 #define	DPRINTF4(str, a, b, c, d)
68 #endif
69 
70 #define	PERROR(string)	my_perror(gettext(string))
71 
72 /* Little endian and big endian */
73 #ifdef sparc
74 #define	les(val)	((((val)&0xFF)<<8)|(((val)>>8)&0xFF))
75 #define	lel(val)	(((unsigned)(les((val)&0x0000FFFF))<<16) | \
76 			(les((unsigned)((val)&0xffff0000)>>16)))
77 #else	/* !sparc */
78 #define	les(val)	(val)
79 #define	lel(val)	(val)
80 #endif /* sparc */
81 
82 /* To avoid misalign access in sparc */
83 #ifdef sparc
84 #define	GET_32(addr)       \
85 	((*((uint8_t *)((char *)addr)) << 24) | \
86 	(*((uint8_t *)(((char *)addr)+1)) << 16) |\
87 	(*((uint8_t *)(((char *)addr)+2)) << 8) | \
88 	(*((uint8_t *)(((char *)addr)+3))))
89 
90 #else
91 #define	GET_32(addr) (*(uint32_t *)addr)
92 #endif
93 
94 #define	VERIFY_READ 1
95 #define	VERIFY_WRITE 2
96 
97 /* w_flag and others */
98 #define	WP_MSG_0 "Medium is already write protected\n"
99 #define	WP_MSG_1 "Medium is password protected : use -W option.\n"
100 #define	WP_MSG_2 "Medium is Read Write protected : use -R option.\n"
101 #define	WP_MSG_3 "Medium is not Write protected\n"
102 
103 /* W_flag */
104 #define	WP_MSG_4 "Medium is Read Write protected.\n"
105 #define	WP_MSG_5 "Changing to write protect with password.\n"
106 #define	WP_MSG_6 "Medium is already password protected\n"
107 #define	WP_MSG_7 "Medium is not password protected\n"
108 
109 /* R_flag */
110 
111 /* Misc */
112 #define	WP_MSG_8 "Medium is password write protected\n"
113 #define	WP_MSG_9 "Changing to Read Write protected\n"
114 #define	WP_MSG_10 "Wrong password or access denied\n"
115 #define	WP_UNKNOWN "Error, can not determine the state of the medium\n"
116 #define	WP_ERROR   "Error, write protect operation failed\n"
117 
118 /*
119  * Condition to be checked for a device
120  */
121 #define	CHECK_TYPE_NOT_CDROM		1
122 #define	CHECK_DEVICE_NOT_READY		2
123 #define	CHECK_DEVICE_NOT_WRITABLE	4
124 #define	CHECK_NO_MEDIA			8
125 #define	CHECK_MEDIA_IS_NOT_WRITABLE	0x10
126 #define	CHECK_MEDIA_IS_NOT_BLANK	0x20
127 #define	CHECK_MEDIA_IS_NOT_ERASABLE	0x40
128 #define	CHECK_DEVICE_IS_CD_WRITABLE	0x100
129 #define	CHECK_DEVICE_IS_DVD_WRITABLE	0x200
130 #define	CHECK_DEVICE_IS_DVD_READABLE	0x400
131 
132 #define	INQUIRY_DATA_LENGTH		96
133 #define	DVD_CONFIG_SIZE			0x20
134 
135 extern int uscsi_error;	/* used for debugging failed uscsi */
136 
137 /* fdisk related structures */
138 
139 struct fdisk_part {
140 	uint8_t    bootid;   /* Bootable? (Active/Inactive) */
141 	uint8_t    systid; /* OS type */
142 	uint32_t   relsect; /* Beginning of partition */
143 	uint32_t   numsect;
144 };
145 
146 struct fdisk_info {
147 	struct fdisk_part part[FD_NUMPART];
148 };
149 
150 typedef struct device {
151 	char		*d_node;
152 	char		*d_name;
153 	int		d_fd;
154 	uchar_t		*d_inq;
155 } device_t;
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif /* _RMFORMAT_H */
162