2 * file.h - definitions for file(1) program
3 * @(#)Id: file.h,v 1.43 2002/07/03 18:57:52 christos Exp
5 * Copyright (c) Ian F. Darwin, 1987.
6 * Written by Ian F. Darwin.
8 * This software is not subject to any license of the American Telephone
9 * and Telegraph Company or of the Regents of the University of California.
11 * Permission is granted to anyone to use this software for any purpose on
12 * any computer system, and to alter it and redistribute it freely, subject
13 * to the following restrictions:
15 * 1. The author is not responsible for the consequences of use of this
16 * software, no matter how awful, even if they arise from flaws in it.
18 * 2. The origin of this software must not be misrepresented, either by
19 * explicit claim or by omission. Since few users ever read sources,
20 * credits must appear in the documentation.
22 * 3. Altered versions must be plainly marked as such, and must not be
23 * misrepresented as being the original software. Since few users
24 * ever read sources, credits must appear in the documentation.
26 * 4. This notice may not be removed or altered.
33 # define HOWMANY 65536 /* how much of the file to look at */
35 #define MAXMAGIS 4096 /* max entries in /etc/magic */
36 #define MAXDESC 50 /* max leng of text description */
37 #define MAXstring 32 /* max leng of "string" types */
39 #define MAGICNO 0xF11E041C
46 uint16_t cont_level; /* level of ">" */
47 uint8_t nospflag; /* supress space character */
49 #define INDIR 1 /* if '>(...)' appears, */
50 #define UNSIGNED 2 /* comparison is unsigned */
51 #define OFFADD 4 /* if '>&' appears, */
52 uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
53 uint8_t vallen; /* length of string value, if any */
54 uint8_t type; /* int, short, long or string. */
55 uint8_t in_type; /* type of indirrection */
72 uint8_t in_op; /* operator for indirection */
73 uint8_t mask_op; /* operator for mask */
82 #define OPINVERSE 0x80
83 int32_t offset; /* offset to magic number */
84 int32_t in_offset; /* offset from indirection */
91 uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */
92 uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */
93 } value; /* either number or string */
94 uint32_t mask; /* mask before comparison with value */
95 char desc[MAXDESC]; /* description */
96 } __attribute__((__packed__));
98 #define BIT(A) (1 << (A))
99 #define STRING_IGNORE_LOWERCASE BIT(0)
100 #define STRING_COMPACT_BLANK BIT(1)
101 #define STRING_COMPACT_OPTIONAL_BLANK BIT(2)
102 #define CHAR_IGNORE_LOWERCASE 'c'
103 #define CHAR_COMPACT_BLANK 'B'
104 #define CHAR_COMPACT_OPTIONAL_BLANK 'b'
107 /* list of magic entries */
109 struct magic *magic; /* array of magic entries */
110 uint32_t nmagic; /* number of entries in array */
117 /*@unchecked@*/ /*@observer@*/ /*@null@*/
118 extern char *progname; /* the program name */
119 /*@unchecked@*/ /*@dependent@*/ /*@observer@*/
120 extern const char *magicfile; /* name of the magic file */
122 extern int lineno; /* current line number in magic file */
125 extern struct mlist mlist; /* list of arrays of magic entries */
129 extern int debug; /* enable debugging? */
131 extern int bflag; /* brief output format */
133 extern int iflag; /* Output types as mime-types */
135 extern int kflag; /* Keep going after the first match */
137 extern int lflag; /* follow symbolic links? */
139 extern int sflag; /* read/analyze block special files? */
141 extern int zflag; /* process compressed files? */
145 extern int apprentice(const char *fn, int action)
146 /*@globals lineno, mlist, fileSystem, internalState @*/
147 /*@modifies lineno, mlist, fileSystem, internalState @*/;
148 extern int ascmagic(unsigned char *buf, int nbytes)
149 /*@globals fileSystem @*/
150 /*@modifies fileSystem @*/;
152 extern void error(const char *f, ...)
153 /*@globals fileSystem @*/
154 /*@modifies fileSystem @*/;
155 extern void ckfputs(const char *str, FILE *fil)
156 /*@globals fileSystem @*/
157 /*@modifies fil, fileSystem @*/;
159 extern int fsmagic(const char *fn, /*@out@*/ struct stat *sb)
160 /*@globals fileSystem, internalState @*/
161 /*@modifies *sb, fileSystem, internalState @*/;
163 extern char *fmttime(long v, int local)
165 extern int is_tar(unsigned char *buf, int nbytes)
167 extern void magwarn(const char *f, ...)
168 /*@globals fileSystem @*/
169 /*@modifies fileSystem @*/;
170 extern void mdump(struct magic *m)
171 /*@globals fileSystem @*/
172 /*@modifies fileSystem @*/;
173 extern void process(const char *inname, int wid)
174 /*@globals fileSystem, internalState @*/
175 /*@modifies fileSystem, internalState @*/;
176 extern void showstr(FILE *fp, const char *s, int len)
177 /*@globals fileSystem @*/
178 /*@modifies fp, fileSystem @*/;
179 extern int softmagic(unsigned char *buf, int nbytes)
180 /*@globals fileSystem @*/
181 /*@modifies buf, fileSystem @*/;
182 extern int tryit(const char *fn, unsigned char *buf, int nb, int zfl)
183 /*@globals fileSystem, internalState @*/
184 /*@modifies buf, fileSystem, internalState @*/;
187 /*@unused@*/ /*@exits@*/ /*@only@*/
188 static inline void * vmefail(/*@unused@*/ size_t nb)
189 /*@globals fileSystem @*/
190 /*@modifies fileSystem @*/
192 error("out of memory");
198 extern int zmagic(const char *fname, unsigned char *buf, int nbytes)
199 /*@globals fileSystem, internalState @*/
200 /*@modifies buf, fileSystem, internalState @*/;
201 extern void ckfprintf(FILE *f, const char *fmt, ...)
202 /*@globals fileSystem @*/
203 /*@modifies f, fileSystem @*/;
204 extern uint32_t signextend(struct magic *m, uint32_t v)
205 /*@globals fileSystem @*/
206 /*@modifies fileSystem @*/;
207 extern void tryelf(int fd, unsigned char *buf, int nbytes)
208 /*@globals fileSystem, internalState @*/
209 /*@modifies fileSystem, internalState @*/;
210 extern int pipe2file(int fd, void *startbuf, size_t nbytes)
211 /*@globals errno, fileSystem, internalState @*/
212 /*@modifies errno, fileSystem, internalState @*/;
214 #endif /* __file_h__ */