xref: /titanic_41/usr/src/cmd/sgs/ar/common/inc.h (revision a62774df315360f02521d6470eab7d5080137dad)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  *	Use is subject to license terms.
24  */
25 
26 /*
27  *	Copyright (c) 1988 AT&T
28  *	  All Rights Reserved
29  *
30  */
31 
32 #ifndef	_INC_H
33 #define	_INC_H
34 
35 #include <stdio.h>
36 #include <sys/param.h>
37 #include <ar.h>
38 #include <errno.h>
39 #include <ctype.h>
40 #include <unistd.h>
41 #include "sgs.h"
42 #include <stdarg.h>
43 #include <sys/mman.h>
44 
45 #ifndef	UID_NOBODY
46 #define	UID_NOBODY	60001
47 #endif
48 
49 #ifndef GID_NOBODY
50 #define	GID_NOBODY	60001
51 #endif
52 
53 #include <stdlib.h>
54 
55 #include "libelf.h"
56 
57 #include <signal.h>
58 #include <sys/stat.h>
59 #include <errno.h>
60 #include <string.h>
61 #include <fcntl.h>
62 
63 #include <time.h>
64 #include <locale.h>
65 
66 #define	SUID	04000
67 #define	SGID	02000
68 #define	ROWN	0400
69 #define	WOWN	0200
70 #define	XOWN	0100
71 #define	RGRP	040
72 #define	WGRP	020
73 #define	XGRP	010
74 #define	ROTH	04
75 #define	WOTH	02
76 #define	XOTH	01
77 #define	STXT	01000
78 
79 #define	opt_FLAG(_x, ch)	((_x->opt_flgs & ch))
80 #define	CHUNK		500
81 #define	SYMCHUNK	1000
82 #define	SNAME		16
83 #define	ROUNDUP(x)	(((x) + 1) & ~1)
84 
85 #define	LONGDIRNAME	"//              "
86 #define	SYMDIRNAME	"/               "	/* symbol directory filename */
87 #define	FNFORMAT	"%-16s"				/* filename format */
88 #define	TLFORMAT	"%-12ld%-6u%-6u%-8o%-10ld%-2s"	/* trailer format */
89 #define	FORMAT		FNFORMAT TLFORMAT
90 #define	DATESIZE	60	 /*  sizeof (struct ar_hdr)  */
91 
92 #define	PLAIN_ERROR	0
93 #define	LIBELF_ERROR	1
94 #define	SYSTEM_ERROR	2
95 
96 typedef struct arfile ARFILE;
97 typedef ARFILE * ARFILEP;
98 
99 #define	AR_MAX_BYTES_IN_MEM		0x20000000 /* 512 Mb */
100 
101 struct arfile
102 {
103 	char	ar_name[SNAME];		/* info from archive member header */
104 	time_t	ar_date;
105 	int	ar_uid;
106 	int	ar_gid;
107 	unsigned long	ar_mode;
108 	long	ar_size;
109 	char    *ar_longname;
110 	char    *ar_rawname;
111 	Elf 	*ar_elf;		/* My elf descriptor */
112 	char	*ar_pathname;
113 	char	*ar_contents;
114 	long	ar_offset;		/* The member offset */
115 	unsigned char ar_flag;
116 	unsigned char ar_padding;	/* padding for CLASS64 */
117 	ARFILE	*ar_next;
118 };
119 
120 typedef struct cmd_info {
121 	char *arnam;	/* Archive file name */
122 	int afd;	/* fd for the archive file */
123 	Elf *arf;	/* Elf descriptor for the archive */
124 	char *ponam;
125 	char **namv;
126 	int namc;
127 	int opt_flgs;	/* lower case options */
128 	int OPT_flgs;	/* upper case options */
129 	int (*comfun)();
130 	int modified;
131 	unsigned long bytes_in_mem;
132 } Cmd_info;
133 
134 /*
135  * options
136  */
137 #define	a_FLAG	0x0001
138 #define	b_FLAG	0x0002
139 #define	c_FLAG	0x0004
140 #define	d_FLAG	0x0008
141 #define	l_FLAG	0x0020
142 #define	m_FLAG	0x0040
143 #define	p_FLAG	0x0080
144 #define	q_FLAG	0x0100
145 #define	r_FLAG	0x0200
146 #define	s_FLAG	0x0400
147 #define	t_FLAG	0x0800
148 #define	u_FLAG	0x1000
149 #define	v_FLAG	0x2000
150 #define	x_FLAG	0x4000
151 #define	z_FLAG	0x8000
152 
153 #define	C_FLAG	0x0001
154 #define	M_FLAG	0x0002
155 #define	T_FLAG	0x0004
156 
157 /*
158  * Where is the file contents from ?
159  */
160 #define	F_ELFRAW	0x01		/* Mmaped via elf_raw() */
161 #define	F_MMAPED	0x02		/* Mmaped file contents */
162 #define	F_MALLOCED	0x04		/* Malloced file contents */
163 #define	F_CLASS32	0x08		/* This is ELFCLASS32 */
164 #define	F_CLASS64	0x10		/* This is ELFCLASS64 */
165 
166 /*
167  * Function prototypes
168  */
169 int qcmd(Cmd_info *);
170 int rcmd(Cmd_info *);
171 int dcmd(Cmd_info *);
172 int xcmd(Cmd_info *);
173 int pcmd(Cmd_info *);
174 int mcmd(Cmd_info *);
175 int tcmd(Cmd_info *);
176 
177 int getaf(Cmd_info *);
178 char *writefile(Cmd_info *cmd_info);
179 void error_message(int, ...);
180 
181 ARFILE *getfile(Cmd_info *);
182 ARFILE *newfile();
183 
184 char *trim(char *);
185 
186 /*
187  * Error definitions
188  */
189 #define	MALLOC_ERROR		0
190 #define	USAGE_01_ERROR		1
191 #define	NOT_FOUND_01_ERROR	2
192 #define	USAGE_02_ERROR		3
193 #define	USAGE_03_ERROR		4
194 #define	USAGE_04_ERROR		5
195 #define	SYS_OPEN_ERROR		6
196 #define	SYS_READ_ERROR		7
197 #define	NOT_FOUND_02_ERROR	8
198 #define	PATHCONF_ERROR		9
199 #define	SYS_WRITE_ERROR		10
200 #define	LOCALTIME_ERROR		11
201 #define	USAGE_05_ERROR		12
202 #define	ELF_VERSION_ERROR	13
203 #define	NOT_ARCHIVE_ERROR 	14
204 #define	USAGE_06_ERROR		15
205 #define	ELF_MALARCHIVE_ERROR	16
206 #define	SYS_LSEEK_ERROR		17
207 #define	NOT_FOUND_03_ERROR	18
208 #define	SYS_LSEEK_02_ERROR	19
209 #define	SYS_LSEEK_03_ERROR	20
210 #define	SYS_LSEEK_04_ERROR	21
211 #define	DEBUG_INFO_01_ERROR	22
212 #define	DEBUG_INFO_02_ERROR	23
213 #define	ELF_INTERNAL_RAND_ERROR	24
214 #define	ELF_BEGIN_01_ERROR	25
215 #define	DEBUG_INFO_03_ERROR	26
216 #define	ELF_BEGIN_02_ERROR	27
217 #define	ELF_BEGIN_03_ERROR	28
218 #define	ARCHIVE_IN_ARCHIVE_ERROR	29
219 #define	ARCHIVE_USAGE_ERROR	30
220 #define	INTERNAL_01_ERROR	31
221 #define	ELF_GETSCN_01_ERROR	32
222 #define	ELF_GETSCN_02_ERROR	33
223 #define	ELF_GETDATA_01_ERROR	34
224 #define	ELF_GETDATA_02_ERROR	35
225 #define	W_ELF_NO_DATA_01_ERROR	36
226 #define	W_ELF_NO_DATA_02_ERROR	37
227 #define	INTERNAL_02_ERROR	38
228 #define	DIAG_01_ERROR		39
229 #define	BER_MES_CREATE_ERROR	40
230 #define	SYS_CREATE_01_ERROR	41
231 #define	SYS_WRITE_02_ERROR	42
232 #define	BER_MES_WRITE_ERROR	43
233 #define	SYS_WRITE_03_ERROR	44
234 #define	SBROW_01_ERROR		45
235 #define	SBROW_02_ERROR		46
236 #define	SBROW_03_ERROR		47
237 #define	SYMTAB_01_ERROR		48
238 #define	SYMTAB_02_ERROR		49
239 #define	SYMTAB_03_ERROR		50
240 #define	SYMTAB_04_ERROR		51
241 #define	SYMTAB_05_ERROR		52
242 #define	SYMTAB_06_ERROR		53
243 #define	SYMTAB_07_ERROR		54
244 #define	ELF_01_ERROR		55
245 #define	ELF_02_ERROR		56
246 #define	OVERRIDE_WARN_ERROR	57
247 #define	SYS_WRITE_04_ERROR	58
248 #define	WARN_USER_ERROR		59
249 #define	ELF_RAWFILE_ERROR	60
250 
251 #endif	/* _INC_H */
252