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