Home | History | Annotate | Line # | Download | only in libfile
      1 /* @(#)file.h	1.12 09/07/13 joerg */
      2 /*
      3  * file.h - definitions for file(1) program
      4  * @(#)Id: file.h,v 1.25 1997/01/15 19:28:35 christos Exp
      5  *
      6  * Copyright (c) Ian F. Darwin, 1987.
      7  * Written by Ian F. Darwin.
      8  *
      9  * This software is not subject to any export provision of the United States
     10  * Department of Commerce, and may be exported to any country or planet.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice immediately at the beginning of the file, without modification,
     17  *    this list of conditions, and the following disclaimer.
     18  * 2. Redistributions in binary form must reproduce the above copyright
     19  *    notice, this list of conditions and the following disclaimer in the
     20  *    documentation and/or other materials provided with the distribution.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     26  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 #ifndef __file_h__
     36 #define __file_h__
     37 
     38 typedef int Int32_t;
     39 typedef unsigned int UInt32_t;
     40 
     41 #ifndef HOWMANY
     42 # define HOWMANY 8192		/* how much of the file to look at */
     43 #endif
     44 #define MAXMAGIS 1000		/* max entries in /etc/magic */
     45 #define MAXDESC	50		/* max leng of text description */
     46 #define MAXstring 32		/* max leng of "string" types */
     47 
     48 struct magic {
     49 	short flag;
     50 #define INDIR	1		/* if '>(...)' appears,  */
     51 #define	UNSIGNED 2		/* comparison is unsigned */
     52 #define ADD	4		/* if '>&' appears,  */
     53 	short cont_level;	/* level of ">" */
     54 	struct {
     55 		char type;	/* byte short long */
     56 		Int32_t offset;	/* offset from indirection */
     57 	} in;
     58 	Int32_t offset;		/* offset to magic number */
     59 	unsigned char reln;	/* relation (0=eq, '>'=gt, etc) */
     60 	char type;		/* int, short, long or string. */
     61 	char vallen;		/* length of string value, if any */
     62 #define 			BYTE	1
     63 #define				SHORT	2
     64 #define				LONG	4
     65 #define				STRING	5
     66 #define				DATE	6
     67 #define				BESHORT	7
     68 #define				BELONG	8
     69 #define				BEDATE	9
     70 #define				LESHORT	10
     71 #define				LELONG	11
     72 #define				LEDATE	12
     73 	union VALUETYPE {
     74 		unsigned char b;
     75 		unsigned short h;
     76 		UInt32_t l;
     77 		char s[MAXstring];
     78 		unsigned char hs[2];	/* 2 bytes of a fixed-endian "short" */
     79 		unsigned char hl[4];	/* 2 bytes of a fixed-endian "long" */
     80 	} value;		/* either number or string */
     81 	UInt32_t mask;	/* mask before comparison with value */
     82 	char nospflag;		/* supress space character */
     83 	char desc[MAXDESC];	/* description */
     84 };
     85 
     86 #include <stdio.h>
     87 
     88 extern int   init_magic		(char *);
     89 extern int   ascmagic		(unsigned char *, int);
     90 extern void  ckfputs		(const char *, FILE *);
     91 struct stat;
     92 extern int   fsmagic		(const char *, struct stat *);
     93 extern int   is_compress	(const unsigned char *, int *);
     94 extern int   is_tar		(unsigned char *, int);
     95 extern void  magwarn		(const char *, ...);
     96 extern void  mdump		(struct magic *);
     97 extern char *get_magic_magic	(const char *);
     98 extern void  showstr		(FILE *, const char *, int);
     99 extern char *softmagic		(unsigned char *, int);
    100 extern int   tryit		(unsigned char *, int, int);
    101 extern int   zmagic		(unsigned char *, int);
    102 extern void  ckfprintf		(FILE *, const char *, ...);
    103 extern UInt32_t signextend	(struct magic *, UInt32_t);
    104 extern int internatmagic	(unsigned char *, int);
    105 extern void tryelf		(int, char *, int);
    106 
    107 
    108 extern char *progname;		/* the program name 			*/
    109 extern char *magicfile;		/* name of the magic file		*/
    110 
    111 extern struct magic *__f_magic;	/* array of magic entries		*/
    112 extern int __f_nmagic;		/* number of valid magic[]s 		*/
    113 
    114 
    115 extern int debug;		/* enable debugging?			*/
    116 extern int zflag;		/* process compressed files?		*/
    117 extern int lflag;		/* follow symbolic links?		*/
    118 
    119 #endif /* __file_h__ */
    120