Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

file/file.h

Go to the documentation of this file.
00001 /*
00002  * file.h - definitions for file(1) program
00003  * @(#)Id: file.h,v 1.43 2002/07/03 18:57:52 christos Exp 
00004  *
00005  * Copyright (c) Ian F. Darwin, 1987.
00006  * Written by Ian F. Darwin.
00007  *
00008  * This software is not subject to any license of the American Telephone
00009  * and Telegraph Company or of the Regents of the University of California.
00010  *
00011  * Permission is granted to anyone to use this software for any purpose on
00012  * any computer system, and to alter it and redistribute it freely, subject
00013  * to the following restrictions:
00014  *
00015  * 1. The author is not responsible for the consequences of use of this
00016  *    software, no matter how awful, even if they arise from flaws in it.
00017  *
00018  * 2. The origin of this software must not be misrepresented, either by
00019  *    explicit claim or by omission.  Since few users ever read sources,
00020  *    credits must appear in the documentation.
00021  *
00022  * 3. Altered versions must be plainly marked as such, and must not be
00023  *    misrepresented as being the original software.  Since few users
00024  *    ever read sources, credits must appear in the documentation.
00025  *
00026  * 4. This notice may not be removed or altered.
00027  */
00028 
00029 #ifndef __file_h__
00030 #define __file_h__
00031 
00032 /*@-redef@*/
00033 
00034 #ifndef HOWMANY
00035 # define HOWMANY 65536          /* how much of the file to look at */
00036 #endif
00037 #define MAXMAGIS 4096           /* max entries in /etc/magic */
00038 #define MAXDESC 50              /* max leng of text description */
00039 #define MAXstring 32            /* max leng of "string" types */
00040 
00041 #define MAGICNO         0xF11E041C
00042 #define VERSIONNO       1
00043 
00044 #define CHECK   1
00045 #define COMPILE 2
00046 
00047 struct magic {
00048         uint16_t cont_level;    /* level of ">" */
00049         uint8_t nospflag;       /* supress space character */
00050         uint8_t flag;
00051 #define INDIR   1               /* if '>(...)' appears,  */
00052 #define UNSIGNED 2              /* comparison is unsigned */
00053 #define OFFADD  4               /* if '>&' appears,  */
00054         uint8_t reln;           /* relation (0=eq, '>'=gt, etc) */
00055         uint8_t vallen;         /* length of string value, if any */
00056         uint8_t type;           /* int, short, long or string. */
00057         uint8_t in_type;        /* type of indirrection */
00058 #define                         BYTE    1
00059 #define                         SHORT   2
00060 #define                         LONG    4
00061 #define                         STRING  5
00062 #define                         DATE    6
00063 #define                         BESHORT 7
00064 #define                         BELONG  8
00065 #define                         BEDATE  9
00066 #define                         LESHORT 10
00067 #define                         LELONG  11
00068 #define                         LEDATE  12
00069 #define                         PSTRING 13
00070 #define                         LDATE   14
00071 #define                         BELDATE 15
00072 #define                         LELDATE 16
00073 #define                         REGEX   17
00074         uint8_t in_op;          /* operator for indirection */
00075         uint8_t mask_op;        /* operator for mask */
00076 #define                         OPAND   1
00077 #define                         OPOR    2
00078 #define                         OPXOR   3
00079 #define                         OPADD   4
00080 #define                         OPMINUS 5
00081 #define                         OPMULTIPLY      6
00082 #define                         OPDIVIDE        7
00083 #define                         OPMODULO        8
00084 #define                         OPINVERSE       0x80
00085         int32_t offset;         /* offset to magic number */
00086         int32_t in_offset;      /* offset from indirection */
00087         union VALUETYPE {
00088                 uint8_t b;
00089                 uint16_t h;
00090                 uint32_t l;
00091                 char s[MAXstring];
00092                 const char * buf;
00093                 uint8_t hs[2];  /* 2 bytes of a fixed-endian "short" */
00094                 uint8_t hl[4];  /* 4 bytes of a fixed-endian "long" */
00095         } value;                /* either number or string */
00096         uint32_t mask;  /* mask before comparison with value */
00097         char desc[MAXDESC];     /* description */
00098 } __attribute__((__packed__));
00099 
00100 #define BIT(A)   (1 << (A))
00101 #define STRING_IGNORE_LOWERCASE         BIT(0)
00102 #define STRING_COMPACT_BLANK            BIT(1)
00103 #define STRING_COMPACT_OPTIONAL_BLANK   BIT(2)
00104 #define CHAR_IGNORE_LOWERCASE           'c'
00105 #define CHAR_COMPACT_BLANK              'B'
00106 #define CHAR_COMPACT_OPTIONAL_BLANK     'b'
00107 
00108 
00109 /* list of magic entries */
00110 struct mlist {
00111         struct magic *magic;            /* array of magic entries */
00112         uint32_t nmagic;                /* number of entries in array */
00113 /*@relnull@*/
00114         struct mlist *next;
00115 /*@relnull@*/
00116         struct mlist *prev;
00117 };
00118 
00119 enum fmagicFlags_e {
00120 /*@-enummemuse@*/
00121     FMAGIC_FLAGS_NONE           = 0,
00122 /*@=enummemuse@*/
00123     FMAGIC_FLAGS_DEBUG          = (1 << 0),
00124     FMAGIC_FLAGS_BRIEF          = (1 << 1),     
00125     FMAGIC_FLAGS_MIME           = (1 << 2),     
00126     FMAGIC_FLAGS_CONTINUE       = (1 << 3),     
00127     FMAGIC_FLAGS_FOLLOW         = (1 << 4),     
00128     FMAGIC_FLAGS_SPECIAL        = (1 << 5),     
00129     FMAGIC_FLAGS_UNCOMPRESS     = (1 << 6)      
00130 };
00131 
00132 struct fmagic_s {
00133     int flags;                  
00134 /*@dependent@*/ /*@observer@*/ /*@relnull@*/
00135     const char *magicfile;      
00136     int lineno;                 
00137 /*@relnull@*/
00138     struct mlist * mlist;       
00139 /*@relnull@*/
00140     struct mlist * ml;          
00141 /*@observer@*/
00142     const char * fn;            
00143     int fd;                     
00144     struct stat sb;             
00145 /*@relnull@*/
00146     unsigned char * buf;        
00147     int nb;                     
00148     union VALUETYPE val;        
00149     int cls;                    
00150     int swap;                   
00151 /*@dependent@*/
00152     char * obp;                 
00153     size_t nob;                 
00154     char obuf[512];             
00155 };
00156 
00157 typedef /*@abstract@*/ struct fmagic_s * fmagic;
00158 
00159 /*@unchecked@*/
00160 extern fmagic global_fmagic;
00161 
00162 /*@unchecked@*//*@observer@*/
00163 extern const char * default_magicfile;
00164 
00165 #ifdef __cplusplus
00166 extern "C" {
00167 #endif
00168 
00169 /*@mayexit@*/
00170 extern int fmagicSetup(fmagic fm, const char *fn, int action)
00171         /*@globals fileSystem, internalState @*/
00172         /*@modifies fm, fileSystem, internalState @*/;
00173 extern int fmagicProcess(fmagic fm, const char *fn, int wid)
00174         /*@globals fileSystem, internalState @*/
00175         /*@modifies fm, fileSystem, internalState @*/;
00176 
00177 extern int fmagicA(fmagic fm)
00178         /*@modifies fm @*/;
00179 extern int fmagicD(fmagic fm)
00180         /*@globals fileSystem, internalState @*/
00181         /*@modifies fm, fileSystem, internalState @*/;
00182 extern void fmagicE(fmagic fm)
00183         /*@globals fileSystem, internalState @*/
00184         /*@modifies fm, fileSystem, internalState @*/;
00185 extern int fmagicF(fmagic fm, int zfl)
00186         /*@globals fileSystem, internalState @*/
00187         /*@modifies fm, fileSystem, internalState @*/;
00188 extern int fmagicS(fmagic fm)
00189         /*@globals fileSystem @*/
00190         /*@modifies fm, fileSystem @*/;
00191 extern int fmagicZ(fmagic fm)
00192         /*@globals fileSystem, internalState @*/
00193         /*@modifies fm, fileSystem, internalState @*/;
00194 
00195 extern void fmagicPrintf(const fmagic fm, const char *f, ...)
00196         /*@modifies fm @*/;
00197 
00198 /*@observer@*/
00199 extern char *fmttime(long v, int local)
00200         /*@*/;
00201 
00202 extern void magwarn(const char *f, ...)
00203         /*@globals fileSystem @*/
00204         /*@modifies fileSystem @*/;
00205 extern void mdump(struct magic *m)
00206         /*@globals fileSystem @*/
00207         /*@modifies fileSystem @*/;
00208 extern void showstr(FILE *fp, const char *s, int len)
00209         /*@globals fileSystem @*/
00210         /*@modifies fp, fileSystem @*/;
00211 
00212 extern uint32_t signextend(struct magic *m, uint32_t v)
00213         /*@globals fileSystem @*/
00214         /*@modifies fileSystem @*/;
00215 extern int pipe2file(int fd, void *startbuf, size_t nbytes)
00216         /*@globals errno, fileSystem, internalState @*/
00217         /*@modifies errno, fileSystem, internalState @*/;
00218 
00219 #ifdef __cplusplus
00220 }
00221 #endif
00222 
00223 /*@=redef@*/
00224 #endif /* __file_h__ */

Generated on Sun Oct 26 13:01:58 2003 for rpm by doxygen1.2.18