Merge from vendor branch BSDTAR:
[dragonfly.git] / sbin / jscan / subs.c
1 /*
2  * Copyright (c) 2004,2005 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  * 
34  * $DragonFly: src/sbin/jscan/subs.c,v 1.2 2005/03/07 05:05:04 dillon Exp $
35  */
36
37 #include "jscan.h"
38
39 void
40 jf_warn(struct jfile *jf, const char *ctl, ...)
41 {
42     va_list va;
43
44     fprintf(stderr, "@0x%016llx ", jf->jf_pos);
45     va_start(va, ctl);
46     vfprintf(stderr, ctl, va);
47     va_end(va);
48     fprintf(stderr, "\n");
49 }
50
51 const char *
52 type_to_name(int16_t rectype)
53 {
54     const char *str;
55
56     switch((u_int16_t)rectype & ~JMASK_LAST) {
57     case JLEAF_PAD:
58         str = "PAD";
59         break;
60     case JLEAF_ABORT:
61         str = "ABORT";
62         break;
63     case JTYPE_ASSOCIATE:
64         str = "ASSOCIATE";
65         break;
66     case JTYPE_DISASSOCIATE:
67         str = "DISASSOCIATE";
68         break;
69     case JTYPE_UNDO:
70         str = "UNDO";
71         break;
72     case JTYPE_AUDIT:
73         str = "AUDIT";
74         break;
75     case JTYPE_SETATTR:
76         str = "SETATTR";
77         break;
78     case JTYPE_WRITE:
79         str = "WRITE";
80         break;
81     case JTYPE_PUTPAGES:
82         str = "PUTPAGES";
83         break;
84     case JTYPE_SETACL:
85         str = "SETACL";
86         break;
87     case JTYPE_SETEXTATTR:
88         str = "SETEXTATTR";
89         break;
90     case JTYPE_CREATE:
91         str = "CREATE";
92         break;
93     case JTYPE_MKNOD:
94         str = "MKNOD";
95         break;
96     case JTYPE_LINK:
97         str = "LINK";
98         break;
99     case JTYPE_SYMLINK:
100         str = "SYMLINK";
101         break;
102     case JTYPE_WHITEOUT:
103         str = "WHITEOUT";
104         break;
105     case JTYPE_REMOVE:
106         str = "REMOVE";
107         break;
108     case JTYPE_MKDIR:
109         str = "MKDIR";
110         break;
111     case JTYPE_RMDIR:
112         str = "RMDIR";
113         break;
114     case JTYPE_RENAME:
115         str = "RENAME";
116         break;
117     case JTYPE_VATTR:
118         str = "vattr";
119         break;
120     case JTYPE_CRED:
121         str = "cred";
122         break;
123     case JLEAF_FILEDATA:
124         str = "filedata";
125         break;
126     case JLEAF_PATH1:
127         str = "path1";
128         break;
129     case JLEAF_PATH2:
130         str = "path2";
131         break;
132     case JLEAF_PATH3:
133         str = "path3";
134         break;
135     case JLEAF_PATH4:
136         str = "path4";
137         break;
138     case JLEAF_UID:
139         str = "uid";
140         break;
141     case JLEAF_GID:
142         str = "gid";
143         break;
144     case JLEAF_MODES:
145         str = "modes";
146         break;
147     case JLEAF_FFLAGS:
148         str = "fflags";
149         break;
150     case JLEAF_PID:
151         str = "pid";
152         break;
153     case JLEAF_PPID:
154         str = "ppid";
155         break;
156     case JLEAF_COMM:
157         str = "comm";
158         break;
159     case JLEAF_ATTRNAME:
160         str = "attrname";
161         break;
162     case JLEAF_PATH_REF:
163         str = "path_ref";
164         break;
165     case JLEAF_RESERVED_0F:
166         str = "?";
167         break;
168     case JLEAF_SYMLINKDATA:
169         str = "symlinkdata";
170         break;
171     case JLEAF_SEEKPOS:
172         str = "seekpos";
173         break;
174     case JLEAF_INUM:
175         str = "inum";
176         break;
177     case JLEAF_NLINK:
178         str = "nlink";
179         break;
180     case JLEAF_FSID:
181         str = "fsid";
182         break;
183     case JLEAF_SIZE:
184         str = "size";
185         break;
186     case JLEAF_ATIME:
187         str = "atime";
188         break;
189     case JLEAF_MTIME:
190         str = "mtime";
191         break;
192     case JLEAF_CTIME:
193         str = "ctime";
194         break;
195     case JLEAF_GEN:
196         str = "gen";
197         break;
198     case JLEAF_FLAGS:
199         str = "flags";
200         break;
201     case JLEAF_UDEV:
202         str = "udev";
203         break;
204     case JLEAF_FILEREV:
205         str = "filerev";
206         break;
207     default:
208         str = "?";
209         break;
210     }
211     return (str);
212 }
213
214 void
215 stringout(FILE *fp, char c, int exact)
216 {
217     if (c != '\\' && c != '\"' && isprint(c)) {
218         putc(c, fp);
219     } else if (exact == 0) {
220         putc('.', fp);
221     } else if (c == 0) {
222         fprintf(fp, "\\0");
223     } else if (c == '\n') {
224         fprintf(fp, "\\n");
225     } else {
226         fprintf(fp, "\\x%02x", (int)(unsigned char)c);
227     }
228 }
229
230