summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sgs/ar/common/inc.h
blob: 9ef573592489fa9c156e9f082780ba926ece8229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
 */

/*
 *	Copyright (c) 1988 AT&T
 *	  All Rights Reserved
 *
 */

#ifndef	_INC_H
#define	_INC_H

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include <signal.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/param.h>
#include <time.h>
#include <locale.h>
#include <ar.h>
#include <libelf.h>
#include "sgs.h"
#include "msg.h"

#define	CHUNK		500
#define	SYMCHUNK	1000
#define	SNAME		16
#define	ROUNDUP(x)	(((x) + 1) & ~1)

#define	DATESIZE	60	 /*  sizeof (struct ar_hdr)  */

typedef struct arfile ARFILE;
typedef ARFILE *ARFILEP;

/*
 * Per-member state, help on listhead/listend list.
 */
struct arfile {
	char		ar_name[SNAME];	/* info from archive member header */
	time_t		ar_date;
	int		ar_uid;
	int		ar_gid;
	unsigned long	ar_mode;
	size_t		ar_size;
	char    	*ar_longname;
	char    	*ar_rawname;
	Elf 		*ar_elf;	/* My elf descriptor */
	char		*ar_pathname;
	char		*ar_contents;
	size_t		ar_offset;	/* The member offset */
	unsigned char	ar_flag;
	unsigned char	ar_padding;	/* # padding bytes following data */
	ARFILE		*ar_next;	/* Next member in linked list or NULL */
};

/*
 * Command function. There is one of these for each operation
 * ar can perform (r, x, etc).
 */
struct cmd_info;
typedef void Cmd_func(struct cmd_info *);

/* Command information block */
typedef struct cmd_info {
	char		*arnam;		/* Archive file name */
	int		afd;		/* fd for the archive file */
	Elf		*arf;		/* Elf descriptor for the archive */
	char		*ponam;		/* Position Name (-a, -b/-i) */
	char		**namv;		/* Member names from command line */
	int		namc;		/* # of member names in namv */
	int		opt_flgs;	/* options */
	Cmd_func	*comfun;	/* function to carry out command */
	int		modified;	/* Set if need to write archive */
} Cmd_info;

/*
 * options (Cmd_info opt_flgs)
 */
#define	a_FLAG	0x00000001
#define	b_FLAG	0x00000002
#define	c_FLAG	0x00000004
#define	C_FLAG	0x00000008
#define	d_FLAG	0x00000010
#define	m_FLAG	0x00000020
#define	p_FLAG	0x00000040
#define	q_FLAG	0x00000080
#define	r_FLAG	0x00000100
#define	s_FLAG	0x00000200
#define	S_FLAG	0x00000400
#define	t_FLAG	0x00000800
#define	T_FLAG	0x00001000
#define	u_FLAG	0x00002000
#define	v_FLAG	0x00004000
#define	x_FLAG	0x00008000
#define	z_FLAG	0x00010000

/*
 * Member flags (ARFILE ar_flag)
 */
#define	F_ELFRAW	0x01		/* ar_contents data via elf_rawfile */
#define	F_CLASS32	0x02		/* ELFCLASS32 */
#define	F_CLASS64	0x04		/* ELFCLASS64 */

/*
 * Function prototypes
 */
Cmd_func	qcmd;
Cmd_func	rcmd;
Cmd_func	dcmd;
Cmd_func	xcmd;
Cmd_func	pcmd;
Cmd_func	mcmd;
Cmd_func	tcmd;

extern ARFILE	*listhead, *listend;

extern	void	establish_sighandler(void (*)());
extern	int	getaf(Cmd_info *);
extern	ARFILE	*getfile(Cmd_info *);
extern	ARFILE	*newfile(void);
extern	char	*trim(char *);
extern	void	writefile(Cmd_info *cmd_info);


#endif	/* _INC_H */