build/rpmfile.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) Ian F. Darwin 1986-1995.
00003  * Software written by Ian F. Darwin and others;
00004  * maintained 1995-present by Christos Zoulas and others.
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice immediately at the beginning of the file, without modification,
00011  *    this list of conditions, and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  *  
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00017  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
00020  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00022  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00023  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00024  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00025  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00026  * SUCH DAMAGE.
00027  */
00028 /*
00029  * file.h - definitions for file(1) program
00030  * @(#)$Id: file.h,v 1.68 2005/06/25 15:52:14 christos Exp $
00031  */
00032 
00033 #ifndef __file_h__
00034 #define __file_h__
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include <config.h>
00038 #endif
00039 
00040 #include <stdio.h>      /* Include that here, to make sure __P gets defined */
00041 #include <errno.h>
00042 #ifdef HAVE_STDINT_H
00043 #include <stdint.h>
00044 #endif
00045 #ifdef HAVE_INTTYPES_H
00046 #include <inttypes.h>
00047 #endif
00048 /* Do this here and now, because struct stat gets re-defined on solaris */
00049 #include <sys/stat.h>
00050 
00051 #ifndef MAGIC
00052 #define MAGIC "/etc/magic"
00053 #endif
00054 
00055 #ifdef __EMX__
00056 #define PATHSEP ';'
00057 #else
00058 #define PATHSEP ':'
00059 #endif
00060 
00061 #define private static
00062 #ifndef protected
00063 #define protected
00064 #endif
00065 #define public
00066 
00067 #ifndef HOWMANY
00068 # define HOWMANY (256 * 1024)   /* how much of the file to look at */
00069 #endif
00070 #define MAXMAGIS 8192           /* max entries in /etc/magic */
00071 #define MAXDESC 64              /* max leng of text description */
00072 #define MAXstring 32            /* max leng of "string" types */
00073 
00074 #define MAGICNO         0xF11E041C
00075 #define VERSIONNO       2
00076 #define FILE_MAGICSIZE  (32 * 4)
00077 
00078 #define FILE_LOAD       0
00079 #define FILE_CHECK      1
00080 #define FILE_COMPILE    2
00081 
00082 struct magic {
00083         /* Word 1 */
00084         uint16_t cont_level;    /* level of ">" */
00085         uint8_t nospflag;       /* supress space character */
00086         uint8_t flag;
00087 #define INDIR   1               /* if '>(...)' appears,  */
00088 #define UNSIGNED 2              /* comparison is unsigned */
00089 #define OFFADD  4               /* if '>&' appears,  */
00090 #define INDIROFFADD     8       /* if '>&(' appears,  */
00091         /* Word 2 */
00092         uint8_t reln;           /* relation (0=eq, '>'=gt, etc) */
00093         uint8_t vallen;         /* length of string value, if any */
00094         uint8_t type;           /* int, short, long or string. */
00095         uint8_t in_type;        /* type of indirrection */
00096 #define                         FILE_BYTE       1
00097 #define                         FILE_SHORT      2
00098 #define                         FILE_LONG       4
00099 #define                         FILE_STRING     5
00100 #define                         FILE_DATE       6
00101 #define                         FILE_BESHORT    7
00102 #define                         FILE_BELONG     8
00103 #define                         FILE_BEDATE     9
00104 #define                         FILE_LESHORT    10
00105 #define                         FILE_LELONG     11
00106 #define                         FILE_LEDATE     12
00107 #define                         FILE_PSTRING    13
00108 #define                         FILE_LDATE      14
00109 #define                         FILE_BELDATE    15
00110 #define                         FILE_LELDATE    16
00111 #define                         FILE_REGEX      17
00112 #define                         FILE_BESTRING16 18
00113 #define                         FILE_LESTRING16 19
00114 #define                         FILE_SEARCH     20
00115 
00116 #define                         FILE_FORMAT_NAME        \
00117 /* 0 */                         "invalid 0",            \
00118 /* 1 */                         "byte",                 \
00119 /* 2 */                         "short",                \
00120 /* 3 */                         "invalid 3",            \
00121 /* 4 */                         "long",                 \
00122 /* 5 */                         "string",               \
00123 /* 6 */                         "date",                 \
00124 /* 7 */                         "beshort",              \
00125 /* 8 */                         "belong",               \
00126 /* 9 */                         "bedate",               \
00127 /* 10 */                        "leshort",              \
00128 /* 11 */                        "lelong",               \
00129 /* 12 */                        "ledate",               \
00130 /* 13 */                        "pstring",              \
00131 /* 14 */                        "ldate",                \
00132 /* 15 */                        "beldate",              \
00133 /* 16 */                        "leldate",              \
00134 /* 17 */                        "regex",                \
00135 /* 18 */                        "bestring16",           \
00136 /* 19 */                        "lestring16",           \
00137 /* 20 */                        "search",
00138 
00139 #define FILE_FMT_NUM    "cduxXi"
00140 #define FILE_FMT_STR    "s"     
00141 
00142 #define                         FILE_FORMAT_STRING      \
00143 /* 0 */                         NULL,                   \
00144 /* 1 */                         FILE_FMT_NUM,           \
00145 /* 2 */                         FILE_FMT_NUM,           \
00146 /* 3 */                         NULL,                   \
00147 /* 4 */                         FILE_FMT_NUM,           \
00148 /* 5 */                         FILE_FMT_STR,           \
00149 /* 6 */                         FILE_FMT_STR,           \
00150 /* 7 */                         FILE_FMT_NUM,           \
00151 /* 8 */                         FILE_FMT_NUM,           \
00152 /* 9 */                         FILE_FMT_STR,           \
00153 /* 10 */                        FILE_FMT_NUM,           \
00154 /* 11 */                        FILE_FMT_NUM,           \
00155 /* 12 */                        FILE_FMT_STR,           \
00156 /* 13 */                        FILE_FMT_STR,           \
00157 /* 14 */                        FILE_FMT_STR,           \
00158 /* 15 */                        FILE_FMT_STR,           \
00159 /* 16 */                        FILE_FMT_STR,           \
00160 /* 17 */                        FILE_FMT_STR,           \
00161 /* 18 */                        FILE_FMT_STR,           \
00162 /* 19 */                        FILE_FMT_STR,           \
00163 /* 20 */                        FILE_FMT_STR,
00164 
00165         /* Word 3 */
00166         uint8_t in_op;          /* operator for indirection */
00167         uint8_t mask_op;        /* operator for mask */
00168         uint8_t dummy1; 
00169         uint8_t dummy2; 
00170 #define                         FILE_OPS        "&|^+-*/%"
00171 #define                         FILE_OPAND      0
00172 #define                         FILE_OPOR       1
00173 #define                         FILE_OPXOR      2
00174 #define                         FILE_OPADD      3
00175 #define                         FILE_OPMINUS    4
00176 #define                         FILE_OPMULTIPLY 5
00177 #define                         FILE_OPDIVIDE   6
00178 #define                         FILE_OPMODULO   7
00179 #define                         FILE_OPINVERSE  0x40
00180 #define                         FILE_OPINDIRECT 0x80
00181         /* Word 4 */
00182         uint32_t offset;        /* offset to magic number */
00183         /* Word 5 */
00184         int32_t in_offset;      /* offset from indirection */
00185         /* Word 6 */
00186         uint32_t mask;  /* mask before comparison with value */
00187         /* Word 7 */
00188         uint32_t dummy3;
00189         /* Word 8 */
00190         uint32_t dummp4;
00191         /* Words 9-16 */
00192         union VALUETYPE {
00193                 uint8_t b;
00194                 uint16_t h;
00195                 uint32_t l;
00196                 char s[MAXstring];
00197 /*@relnull@*/
00198                 char *buf;
00199                 uint8_t hs[2];  /* 2 bytes of a fixed-endian "short" */
00200                 uint8_t hl[4];  /* 4 bytes of a fixed-endian "long" */
00201         } value;                /* either number or string */
00202         /* Words 17..31 */
00203         char desc[MAXDESC];     /* description */
00204 };
00205 
00206 #define BIT(A)   (1 << (A))
00207 #define STRING_IGNORE_LOWERCASE         BIT(0)
00208 #define STRING_COMPACT_BLANK            BIT(1)
00209 #define STRING_COMPACT_OPTIONAL_BLANK   BIT(2)
00210 #define CHAR_IGNORE_LOWERCASE           'c'
00211 #define CHAR_COMPACT_BLANK              'B'
00212 #define CHAR_COMPACT_OPTIONAL_BLANK     'b'
00213 
00214 
00215 /* list of magic entries */
00216 struct mlist {
00217         struct magic *magic;            /* array of magic entries */
00218         uint32_t nmagic;                        /* number of entries in array */
00219         int mapped;  /* allocation type: 0 => apprentice_file
00220                       *                  1 => apprentice_map + malloc
00221                       *                  2 => apprentice_map + mmap */
00222 /*@dependent@*/
00223         struct mlist *next, *prev;
00224 };
00225 
00226 struct magic_set {
00227 /*@relnull@*/
00228     struct mlist *mlist;
00229     struct cont {
00230         size_t len;
00231 /*@relnull@*/
00232         int32_t *off;
00233     } c;
00234     struct out {
00235         /* Accumulation buffer */
00236 /*@owned@*/ /*@relnull@*/
00237         char *buf;
00238 /*@dependent@*/ /*@relnull@*/
00239         char *ptr;
00240         size_t len;
00241         size_t size;
00242         /* Printable buffer */
00243         char *pbuf;
00244         size_t psize;
00245     } o;
00246     int error;
00247     int flags;
00248     int haderr;
00249     const char *file;
00250     size_t line;
00251 };
00252 
00253 struct stat;
00254 /*@observer@*/
00255 protected const char *file_fmttime(uint32_t, int)
00256         /*@*/;
00257 protected int file_buffer(struct magic_set *ms, int, const void *, size_t)
00258         /*@globals fileSystem, internalState @*/
00259         /*@modifies ms, fileSystem, internalState @*/;
00260 protected int file_fsmagic(struct magic_set *ms, /*@null@*/ const char *fn, struct stat *sb)
00261         /*@modifies ms, sb @*/;
00262 protected int file_pipe2file(struct magic_set *ms, int fd, const void *startbuf, size_t nbytes)
00263         /*@globals errno, fileSystem, internalState @*/
00264         /*@modifies ms, errno, fileSystem, internalState @*/;
00265 protected int file_printf(struct magic_set *ms, const char *, ...)
00266         /*@modifies ms @*/;
00267 protected int file_reset(struct magic_set *ms)
00268         /*@modifies ms @*/;
00269 protected int file_tryelf(struct magic_set *ms, int, const unsigned char *, size_t)
00270         /*@globals fileSystem, internalState @*/
00271         /*@modifies ms, fileSystem, internalState @*/;
00272 protected int file_zmagic(struct magic_set *ms, int, const unsigned char *, size_t)
00273         /*@globals fileSystem, internalState @*/
00274         /*@modifies ms, fileSystem, internalState @*/;
00275 protected int file_ascmagic(struct magic_set *ms, const unsigned char *, size_t)
00276         /*@modifies ms @*/;
00277 protected int file_is_tar(struct magic_set *ms, const unsigned char *, size_t)
00278         /*@modifies ms @*/;
00279 protected int file_softmagic(struct magic_set *ms, const unsigned char *, size_t)
00280         /*@globals fileSystem @*/
00281         /*@modifies ms, fileSystem @*/;
00282 /*@null@*/
00283 protected struct mlist *file_apprentice(struct magic_set *ms, const char *, int)
00284         /*@globals fileSystem, internalState @*/
00285         /*@modifies ms, fileSystem, internalState @*/;
00286 protected uint32_t file_signextend(struct magic_set *ms, struct magic *, uint32_t)
00287         /*@globals fileSystem @*/
00288         /*@modifies ms, fileSystem @*/;
00289 protected void file_delmagic(struct magic *p, int type, size_t entries)
00290         /*@globals fileSystem @*/
00291         /*@modifies p, fileSystem @*/;
00292 protected void file_badread(struct magic_set *ms)
00293         /*@modifies ms @*/;
00294 protected void file_badseek(struct magic_set *ms)
00295         /*@modifies ms @*/;
00296 protected void file_oomem(struct magic_set *ms)
00297         /*@modifies ms @*/;
00298 protected void file_error(struct magic_set *ms, int, const char *, ...)
00299         /*@modifies ms @*/;
00300 protected void file_magwarn(struct magic_set *ms, const char *, ...)
00301         /*@globals fileSystem @*/
00302         /*@modifies fileSystem @*/;
00303 protected void file_mdump(struct magic *m)
00304         /*@globals fileSystem @*/
00305         /*@modifies m, fileSystem @*/;
00306 protected void file_showstr(FILE *fp, const char *, size_t)
00307         /*@globals fileSystem @*/
00308         /*@modifies fp, fileSystem @*/;
00309 protected size_t file_mbswidth(const char *)
00310         /*@*/;
00311 /*@observer@*/
00312 protected const char *file_getbuffer(struct magic_set *ms)
00313         /*@modifies ms @*/;
00314 
00315 #ifndef HAVE_STRERROR
00316 extern int sys_nerr;
00317 extern char *sys_errlist[];
00318 #define strerror(e) \
00319         (((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
00320 #endif
00321 
00322 #ifndef HAVE_STRTOUL
00323 #define strtoul(a, b, c)        strtol(a, b, c)
00324 #endif
00325 
00326 #if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK)
00327 #define QUICK
00328 #endif
00329 
00330 #define FILE_RCSID(id) \
00331 static const char *rcsid(const char *p) { \
00332         return rcsid(p = id); \
00333 }
00334 #else
00335 
00336 #endif /* __file_h__ */

Generated on Mon Mar 5 13:30:26 2007 for rpm by  doxygen 1.5.1