code:
/* Generated from /usr/src/kerberos5/lib/libasn1/../../../crypto/heimdal/lib/asn1/kx509.asn1 */
/* Do not edit */

#ifndef __kx509_asn1_h__
#define __kx509_asn1_h__

#include <stddef.h>
#include <time.h>

#ifndef __asn1_common_definitions__
#define __asn1_common_definitions__

typedef struct heim_integer {
  size_t length;
  void *data;
  int negative;
} heim_integer;

typedef struct heim_octet_string {
  size_t length;
  void *data;
} heim_octet_string;

typedef char *heim_general_string;

typedef char *heim_utf8_string;

typedef char *heim_printable_string;

typedef char *heim_ia5_string;

typedef struct heim_bmp_string {
  size_t length;
  uint16_t *data;
} heim_bmp_string;

typedef struct heim_universal_string {
  size_t length;
  uint32_t *data;
} heim_universal_string;

typedef char *heim_visible_string;

typedef struct heim_oid {
  size_t length;
  unsigned *components;
} heim_oid;

typedef struct heim_bit_string {
  size_t length;
  void *data;
} heim_bit_string;

typedef struct heim_octet_string heim_any;
typedef struct heim_octet_string heim_any_set;

#define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R)                  \
  do {                                                         \
    (BL) = length_##T((S));                                    \
    (B) = malloc((BL));                                        \
    if((B) == NULL) {                                          \
      (R) = ENOMEM;                                            \
    } else {                                                   \
      (R) = encode_##T(((unsigned char*)(B)) + (BL) - 1, (BL), \
                       (S), (L));                              \
      if((R) != 0) {                                           \
        free((B));                                             \
        (B) = NULL;                                            \
      }                                                        \
    }                                                          \
  } while (0)

struct units;

#endif

/*
Kx509Request ::= SEQUENCE {
  authenticator   OCTET STRING,
  pk-hash         OCTET STRING,
  pk-key          OCTET STRING,
}
*/

typedef struct Kx509Request {
  heim_octet_string authenticator;
  heim_octet_string pk_hash;
  heim_octet_string pk_key;
} Kx509Request;

int    encode_Kx509Request(unsigned char *, size_t, const Kx509Request *, size_t *);
int    decode_Kx509Request(const unsigned char *, size_t, Kx509Request *, size_t *);
void   free_Kx509Request  (Kx509Request *);
size_t length_Kx509Request(const Kx509Request *);
int    copy_Kx509Request  (const Kx509Request *, Kx509Request *);

/*
Kx509Response ::= SEQUENCE {
  error-code      [0] INTEGER (-2147483648..2147483647) OPTIONAL,
  hash            [1] OCTET STRING OPTIONAL,
  certificate     [2] OCTET STRING OPTIONAL,
  e-text          [3]   VisibleString OPTIONAL,
}
*/

typedef struct Kx509Response {
  int *error_code;
  heim_octet_string *hash;
  heim_octet_string *certificate;
  heim_visible_string *e_text;
} Kx509Response;

int    encode_Kx509Response(unsigned char *, size_t, const Kx509Response *, size_t *);
int    decode_Kx509Response(const unsigned char *, size_t, Kx509Response *, size_t *);
void   free_Kx509Response  (Kx509Response *);
size_t length_Kx509Response(const Kx509Response *);
int    copy_Kx509Response  (const Kx509Response *, Kx509Response *);

#endif /* __kx509_asn1_h__ */


code:
/*-
 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/include/langinfo.h 197764 2009-10-05 07:11:19Z edwin $
 */

#ifndef _LANGINFO_H_
#define	_LANGINFO_H_

#include <sys/cdefs.h>
#include <sys/_types.h>

#ifndef _NL_ITEM_DECLARED
typedef	__nl_item	nl_item;
#define	_NL_ITEM_DECLARED
#endif

#define	CODESET		0	/* codeset name */
#define	D_T_FMT		1	/* string for formatting date and time */
#define	D_FMT		2	/* date format string */
#define	T_FMT		3	/* time format string */
#define	T_FMT_AMPM	4	/* a.m. or p.m. time formatting string */
#define	AM_STR		5	/* Ante Meridian affix */
#define	PM_STR		6	/* Post Meridian affix */

/* week day names */
#define	DAY_1		7
#define	DAY_2		8
#define	DAY_3		9
#define	DAY_4		10
#define	DAY_5		11
#define	DAY_6		12
#define	DAY_7		13

/* abbreviated week day names */
#define	ABDAY_1		14
#define	ABDAY_2		15
#define	ABDAY_3		16
#define	ABDAY_4		17
#define	ABDAY_5		18
#define	ABDAY_6		19
#define	ABDAY_7		20

/* month names */
#define	MON_1		21
#define	MON_2		22
#define	MON_3		23
#define	MON_4		24
#define	MON_5		25
#define	MON_6		26
#define	MON_7		27
#define	MON_8		28
#define	MON_9		29
#define	MON_10		30
#define	MON_11		31
#define	MON_12		32

/* abbreviated month names */
#define	ABMON_1		33
#define	ABMON_2		34
#define	ABMON_3		35
#define	ABMON_4		36
#define	ABMON_5		37
#define	ABMON_6		38
#define	ABMON_7		39
#define	ABMON_8		40
#define	ABMON_9		41
#define	ABMON_10	42
#define	ABMON_11	43
#define	ABMON_12	44

#define	ERA		45	/* era description segments */
#define	ERA_D_FMT	46	/* era date format string */
#define	ERA_D_T_FMT	47	/* era date and time format string */
#define	ERA_T_FMT	48	/* era time format string */
#define	ALT_DIGITS	49	/* alternative symbols for digits */

#define	RADIXCHAR	50	/* radix char */
#define	THOUSEP		51	/* separator for thousands */

#define	YESEXPR		52	/* affirmative response expression */
#define	NOEXPR		53	/* negative response expression */

#if __BSD_VISIBLE || __XSI_VISIBLE <= 500
#define	YESSTR		54	/* affirmative response for yes/no queries */
#define	NOSTR		55	/* negative response for yes/no queries */
#endif

#define	CRNCYSTR	56	/* currency symbol */

#if __BSD_VISIBLE
#define	D_MD_ORDER	57	/* month/day order (local extension) */
#endif

/* standalone months forms for %OB */
#define	ALTMON_1	58
#define	ALTMON_2	59
#define	ALTMON_3	60
#define	ALTMON_4	61
#define	ALTMON_5	62
#define	ALTMON_6	63
#define	ALTMON_7	64
#define	ALTMON_8	65
#define	ALTMON_9	66
#define	ALTMON_10	67
#define	ALTMON_11	68
#define	ALTMON_12	69

__BEGIN_DECLS
char	*nl_langinfo(nl_item);
__END_DECLS

#endif /* !_LANGINFO_H_ */

repo_name: veiledmerc/mira

license: mit


code:
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
* $FreeBSD: release/9.0.0/lib/libdisk/libdisk.h 178765 2008-05-04 22:24:40Z gonzo $
*
*/

#ifndef _LIBDISK_H_
#define _LIBDISK_H_

/* #define DEBUG 1 */
/* You can define a particular architecture here if you are debugging. */
/* #define P_DEBUG p_sparc64 */

#define MAX_NO_DISKS	32
/* Max # of disks Disk_Names() will return */

#define MAX_SEC_SIZE    2048  /* maximum sector size that is supported */
#define MIN_SEC_SIZE	512   /* the sector size to end sensing at */

enum platform {
	p_any,			/* for debugging ! */
	p_alpha,
	p_i386,
	p_pc98,
	p_sparc64,
	p_ia64,
	p_ppc,
	p_amd64,
	p_arm,
	p_mips
};
extern const enum platform platform;

typedef enum {
	whole,
	unknown,

	sun,
	pc98,
	mbr,
	gpt,

	efi,
	fat,
	freebsd,
	extended,
	part,
	spare,
	unused,

	apple
} chunk_e;

__BEGIN_DECLS
#ifndef __ia64__
struct disk {
	char		*name;
	u_long		bios_cyl;
	u_long		bios_hd;
	u_long		bios_sect;
#ifdef PC98
	u_char		*bootipl;
	size_t		bootipl_size;
	u_char		*bootmenu;
	size_t		bootmenu_size;
#else
	u_char		*bootmgr;
	size_t		bootmgr_size;
#endif
	u_char		*boot1;
#if defined(__i386__) || defined(__amd64__) /* the i386 needs extra help... */
	u_char		*boot2;
#endif
	struct chunk	*chunks;
	u_long		sector_size; /* media sector size, a power of 2 */
};
#else	/* !__ia64__ */
struct disk {
	char		*name;
	struct chunk	*chunks;
	u_long		media_size;
	u_long		sector_size;
	u_long		lba_start;
	u_long		lba_end;
	u_int		gpt_size;	/* Number of entries */
};
#endif

struct chunk {
	struct chunk	*next;
	struct chunk	*part;
	struct disk	*disk;
	daddr_t		offset;
	daddr_t		size;
	daddr_t		end;
	char		*sname;		/* PC98 field */
	char		*name;
	char		*oname;
	/* Used during Fixup_Names() to avoid renaming more than
	 * absolutely needed.
	 */
	chunk_e		type;
	int		subtype;
	u_long		flags;
	void		(*private_free)(void*);
	void		*(*private_clone)(void*);
	void		*private_data;
	/* For data private to the application, and the management
	 * thereof.  If the functions are not provided, no storage
	 * management is done, Cloning will just copy the pointer
	 * and freeing will just forget it.
	 */
};

/*
 * flags:
 *
 * ALIGN	-	This chunk should be aligned
 * IS_ROOT	-	This 'part' is a rootfs, allocate 'a'
 * ACTIVE	-	This is the active slice in the MBR
 * FORCE_ALL	-	Force a dedicated disk for FreeBSD, bypassing
 *			all BIOS geometry considerations
 * AUTO_SIZE	-	This chunk was auto-sized and can fill-out a
 *			following chunk if the following chunk is deleted.
 * NEWFS	-	newfs pending, used to enable auto-resizing on
 *			delete (along with AUTO_SIZE).
 */

#define CHUNK_ALIGN		0x0008
#define CHUNK_IS_ROOT		0x0010
#define CHUNK_ACTIVE		0x0020
#define CHUNK_FORCE_ALL		0x0040
#define CHUNK_AUTO_SIZE		0x0080
#define CHUNK_NEWFS		0x0100
#define	CHUNK_HAS_INDEX		0x0200
#define	CHUNK_ITOF(i)		((i & 0xFFFF) << 16)
#define	CHUNK_FTOI(f)		((f >> 16) & 0xFFFF)

#define DELCHUNK_NORMAL		0x0000
#define DELCHUNK_RECOVER	0x0001

const char *chunk_name(chunk_e);

const char *
slice_type_name(int, int);
/* "chunk_n" for subtypes too */

struct disk *
Open_Disk(const char *);
/* Will open the named disk, and return populated tree.  */

void
Free_Disk(struct disk *);
/* Free a tree made with Open_Disk() or Clone_Disk() */

void
Debug_Disk(struct disk *);
/* Print the content of the tree to stdout */

void
Set_Bios_Geom(struct disk *, u_long, u_long, u_long);
/* Set the geometry the bios uses. */

void
Sanitize_Bios_Geom(struct disk *);
/* Set the bios geometry to something sane */

int
Insert_Chunk(struct chunk *, daddr_t, daddr_t, const char *, chunk_e, int,
	u_long, const char *);

int
Delete_Chunk2(struct disk *, struct chunk *, int);
/* Free a chunk of disk_space modified by the passed flags. */

int
Delete_Chunk(struct disk *, struct chunk *);
/* Free a chunk of disk_space */

void
Collapse_Disk(struct disk *);
/* Experimental, do not use. */

int
Collapse_Chunk(struct disk *, struct chunk *);
/* Experimental, do not use. */

int
Create_Chunk(struct disk *, daddr_t, daddr_t, chunk_e, int, u_long, const char *);
/* Create a chunk with the specified paramters */

void
All_FreeBSD(struct disk *, int);
/*
 * Make one FreeBSD chunk covering the entire disk;
 * if force_all is set, bypass all BIOS geometry
 * considerations.
 */

char *
CheckRules(const struct disk *);
/* Return char* to warnings about broken design rules in this disklayout */

char **
Disk_Names(void);
/*
 * Return char** with all disk's names (wd0, wd1 ...).  You must free
 * each pointer, as well as the array by hand
 */

#ifdef PC98
void
Set_Boot_Mgr(struct disk *, const u_char *, const size_t, const u_char *,
	const size_t);
#else
void
Set_Boot_Mgr(struct disk *, const u_char *, const size_t);
#endif
/*
 * Use this boot-manager on this disk.  Gets written when Write_Disk()
 * is called
 */

int
Set_Boot_Blocks(struct disk *, const u_char *, const u_char *);
/*
 * Use these boot-blocks on this disk.  Gets written when Write_Disk()
 * is called. Returns nonzero upon failure.
 */

int
Write_Disk(const struct disk *);
/* Write all the MBRs, disklabels, bootblocks and boot managers */

daddr_t
Next_Cyl_Aligned(const struct disk *, daddr_t);
/* Round offset up to next cylinder according to the bios-geometry */

daddr_t
Prev_Cyl_Aligned(const struct disk *, daddr_t);
/* Round offset down to previous cylinder according to the bios-geometry */

int
Track_Aligned(const struct disk *, daddr_t);
/* Check if offset is aligned on a track according to the bios geometry */

daddr_t
Next_Track_Aligned(const struct disk *, daddr_t);
/* Round offset up to next track according to the bios-geometry */

daddr_t
Prev_Track_Aligned(const struct disk *, daddr_t);
/* Check if offset is aligned on a track according to the bios geometry */

struct chunk *
Create_Chunk_DWIM(struct disk *, struct chunk *, daddr_t, chunk_e, int,
	u_long);
/*
 * This one creates a partition inside the given parent of the given
 * size, and returns a pointer to it.  The first unused chunk big
 * enough is used.
 */

char *
ShowChunkFlags(struct chunk *);
/* Return string to show flags. */

/*
 * Implementation details  >>> DO NOT USE <<<
 */

struct disklabel;

void Fill_Disklabel(struct disklabel *, const struct disk *,
	const struct chunk *);
void Debug_Chunk(struct chunk *);
struct chunk *New_Chunk(void);
void Free_Chunk(struct chunk *);
struct chunk *Clone_Chunk(const struct chunk *);
int Add_Chunk(struct disk *, daddr_t, daddr_t, const char *, chunk_e, int,
	u_long, const char *);
void *read_block(int, daddr_t, u_long);
int write_block(int, daddr_t, const void *, u_long);
struct disklabel *read_disklabel(int, daddr_t, u_long);
struct disk *Int_Open_Disk(const char *, char *);
int Fixup_Names(struct disk *);
int MakeDevChunk(const struct chunk *, const char *);
__END_DECLS

#define dprintf	printf

/* TODO
 *
 * Need an error string mechanism from the functions instead of warn()
 *
 * Make sure only FreeBSD start at offset==0
 *
 * Collapse must align.
 *
 * Make Write_Disk(struct disk*)
 *
 * Consider booting from OnTrack'ed disks.
 *
 * Get Bios-geom, ST506 & OnTrack from driver (or otherwise)
 *
 * Make Create_DWIM().
 *
 * Make Is_Unchanged(struct disk *d1, struct chunk *c1)
 *
 * don't rename slices unless we have to
 *
 *Sample output from tst01:
 *
 * Debug_Disk(wd0)  flags=0  bios_geom=0/0/0
 * >>        0x3d040          0    1411200    1411199 wd0      0 whole    0 0
 * >>>>      0x3d080          0     960120     960119 wd0s1    3 freebsd  0 8
 * >>>>>>    0x3d100          0      40960      40959 wd0s1a   5 part     0 0
 * >>>>>>    0x3d180      40960     131072     172031 wd0s1b   5 part     0 0
 * >>>>>>    0x3d1c0     172032     409600     581631 wd0s1e   5 part     0 0
 * >>>>>>    0x3d200     581632     378488     960119 wd0s1f   5 part     0 0
 * >>>>      0x3d140     960120       5670     965789 wd0s2    4 extended 0 8
 * >>>>>>    0x3d2c0     960120         63     960182 -        6 unused   0 0
 * >>>>>>    0x3d0c0     960183       5607     965789 wd0s5    2 fat      0 8
 * >>>>      0x3d280     965790       1890     967679 wd0s3    1 foo      -2 8
 * >>>>      0x3d300     967680     443520    1411199 wd0s4    3 freebsd  0 8
 * >>>>>>    0x3d340     967680     443520    1411199 wd0s4a   5 part     0 0
 *
 * ^            ^           ^          ^          ^     ^      ^ ^        ^ ^
 * level    chunkptr      start      size        end  name    type  subtype flags
 *
 * Underlying data structure:
 *
 *	Legend:
 *		<struct chunk> --> part
 *			|
 *			v next
 *
 *	<wd0> --> <wd0s1> --> <wd0s1a>
 *		     |           |
 *		     |           v
 *		     |        <wd0s1b>
 *		     |           |
 *		     |           v
 *		     |        <wd0s1e>
 *		     |           |
 *		     |           v
 *		     |        <wd0s1f>
 *		     |
 *		     v
 *		  <wd0s2> --> <unused>
 *		     |           |
 *		     |           v
 *		     |        <wd0s5>
 *		     |
 *		     v
 *		  <wd0s3>
 *		     |
 *		     v
 *		  <wd0s4> --> <wd0s4a>
 *
 *
 */

#endif /* _LIBDISK_H_ */


code:
/*-
 * Copyright (c) 2007 John Birrell (jb@freebsd.org)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/lib/libdwarf/libdwarf.h 221569 2011-05-07 01:05:31Z obrien $
 */

#ifndef	_LIBDWARF_H_
#define	_LIBDWARF_H_

#include <libelf.h>

typedef int		Dwarf_Bool;
typedef off_t		Dwarf_Off;
typedef uint64_t	Dwarf_Unsigned;
typedef uint16_t	Dwarf_Half;
typedef uint8_t		Dwarf_Small;
typedef int64_t		Dwarf_Signed;
typedef uint64_t	Dwarf_Addr;
typedef void		*Dwarf_Ptr;

/* Forward definitions. */
typedef struct _Dwarf_Abbrev	*Dwarf_Abbrev;
typedef struct _Dwarf_Arange	*Dwarf_Arange;
typedef struct _Dwarf_Attribute	*Dwarf_Attribute;
typedef struct _Dwarf_AttrValue	*Dwarf_AttrValue;
typedef struct _Dwarf_CU	*Dwarf_CU;
typedef struct _Dwarf_Cie	*Dwarf_Cie;
typedef struct _Dwarf_Debug	*Dwarf_Debug;
typedef struct _Dwarf_Die	*Dwarf_Die;
typedef struct _Dwarf_Fde	*Dwarf_Fde;
typedef struct _Dwarf_Func	*Dwarf_Func;
typedef struct _Dwarf_Inlined_Func *Dwarf_Inlined_Func;
typedef struct _Dwarf_Global	*Dwarf_Global;
typedef struct _Dwarf_Line	*Dwarf_Line;
typedef struct _Dwarf_Type	*Dwarf_Type;
typedef struct _Dwarf_Var	*Dwarf_Var;
typedef struct _Dwarf_Weak	*Dwarf_Weak;

typedef struct {
        Dwarf_Small	lr_atom;
        Dwarf_Unsigned	lr_number;
	Dwarf_Unsigned	lr_number2;
	Dwarf_Unsigned	lr_offset;
} Dwarf_Loc;

typedef struct {
	Dwarf_Addr      ld_lopc;
	Dwarf_Addr      ld_hipc;
	Dwarf_Half      ld_cents;
	Dwarf_Loc	*ld_s;
} Dwarf_Locdesc;

/* receiver function for dwarf_function_iterate_inlined_instance() API */
typedef void (*Dwarf_Inlined_Callback)(Dwarf_Inlined_Func, void *);

/*
 * Error numbers which are specific to this implementation.
 */
enum {
	DWARF_E_NONE,			/* No error. */
	DWARF_E_ERROR,			/* An error! */
	DWARF_E_NO_ENTRY,		/* No entry. */
	DWARF_E_ARGUMENT,		/* Invalid argument. */
	DWARF_E_DEBUG_INFO,		/* Debug info NULL. */
	DWARF_E_MEMORY,			/* Insufficient memory. */
	DWARF_E_ELF,			/* ELF error. */
	DWARF_E_INVALID_CU,		/* Invalid compilation unit data. */
	DWARF_E_CU_VERSION,		/* Wrong CU version. */
	DWARF_E_MISSING_ABBREV,		/* Abbrev not found. */
	DWARF_E_NOT_IMPLEMENTED,	/* Not implemented. */
	DWARF_E_CU_CURRENT,		/* No current compilation unit. */
	DWARF_E_BAD_FORM,		/* Wrong form type for attribute value. */
	DWARF_E_INVALID_EXPR,		/* Invalid DWARF expression. */
	DWARF_E_NUM			/* Max error number. */
};

typedef struct _Dwarf_Error {
	int		err_error;	/* DWARF error. */
	int		elf_error;	/* ELF error. */
	const char	*err_func;	/* Function name where error occurred. */
	int		err_line;	/* Line number where error occurred. */
	char		err_msg[1024];	/* Formatted error message. */
} Dwarf_Error;

/*
 * Return values which have to be compatible with other
 * implementations of libdwarf.
 */
#define DW_DLV_NO_ENTRY		DWARF_E_NO_ENTRY
#define DW_DLV_OK		DWARF_E_NONE
#define DW_DLE_DEBUG_INFO_NULL	DWARF_E_DEBUG_INFO

#define DW_DLC_READ        	0	/* read only access */

/* Function prototype definitions. */
__BEGIN_DECLS
Dwarf_Abbrev	dwarf_abbrev_find(Dwarf_CU, uint64_t);
Dwarf_AttrValue dwarf_attrval_find(Dwarf_Die, Dwarf_Half);
Dwarf_Die	dwarf_die_find(Dwarf_Die, Dwarf_Unsigned);
const char	*dwarf_errmsg(Dwarf_Error *);
const char	*get_sht_desc(uint32_t);
const char	*get_attr_desc(uint32_t);
const char	*get_form_desc(uint32_t);
const char	*get_tag_desc(uint32_t);
int		dwarf_abbrev_add(Dwarf_CU, uint64_t, uint64_t, uint8_t, Dwarf_Abbrev *, Dwarf_Error *);
int		dwarf_attr(Dwarf_Die, Dwarf_Half, Dwarf_Attribute *, Dwarf_Error *);
int		dwarf_attr_add(Dwarf_Abbrev, uint64_t, uint64_t, Dwarf_Attribute *, Dwarf_Error *);
int		dwarf_attrval(Dwarf_Die, Dwarf_Half, Dwarf_AttrValue *, Dwarf_Error *);
int		dwarf_attrval_add(Dwarf_Die, Dwarf_AttrValue, Dwarf_AttrValue *, Dwarf_Error *);
int		dwarf_attrval_flag(Dwarf_Die, uint64_t, Dwarf_Bool *, Dwarf_Error *);
int		dwarf_attrval_signed(Dwarf_Die, uint64_t, Dwarf_Signed *, Dwarf_Error *);
int		dwarf_attrval_string(Dwarf_Die, uint64_t, const char **, Dwarf_Error *);
int		dwarf_attrval_unsigned(Dwarf_Die, uint64_t, Dwarf_Unsigned *, Dwarf_Error *);
int		dwarf_child(Dwarf_Die, Dwarf_Die *, Dwarf_Error *);
int		dwarf_die_add(Dwarf_CU, int, uint64_t, uint64_t, Dwarf_Abbrev, Dwarf_Die *, Dwarf_Error *);
int		dwarf_dieoffset(Dwarf_Die, Dwarf_Off *, Dwarf_Error *);
int		dwarf_elf_init(Elf *, int, Dwarf_Debug *, Dwarf_Error *);
int		dwarf_errno(Dwarf_Error *);
int		dwarf_finish(Dwarf_Debug *, Dwarf_Error *);
int		dwarf_locdesc(Dwarf_Die, uint64_t, Dwarf_Locdesc **, Dwarf_Signed *, Dwarf_Error *);
int		dwarf_locdesc_free(Dwarf_Locdesc *, Dwarf_Error *);
int		dwarf_init(int, int, Dwarf_Debug *, Dwarf_Error *);
int		dwarf_next_cu_header(Dwarf_Debug, Dwarf_Unsigned *, Dwarf_Half *,
		    Dwarf_Unsigned *, Dwarf_Half *, Dwarf_Unsigned *, Dwarf_Error *);
int		dwarf_op_num(uint8_t, uint8_t *, int);
int		dwarf_siblingof(Dwarf_Debug, Dwarf_Die, Dwarf_Die *, Dwarf_Error *);
int		dwarf_tag(Dwarf_Die, Dwarf_Half *, Dwarf_Error *);
int		dwarf_whatform(Dwarf_Attribute, Dwarf_Half *, Dwarf_Error *);
void		dwarf_dealloc(Dwarf_Debug, Dwarf_Ptr, Dwarf_Unsigned);
void		dwarf_dump(Dwarf_Debug);
void		dwarf_dump_abbrev(Dwarf_Debug);
void		dwarf_dump_av(Dwarf_Die, Dwarf_AttrValue);
void		dwarf_dump_dbgstr(Dwarf_Debug);
void		dwarf_dump_die(Dwarf_Die);
void		dwarf_dump_die_at_offset(Dwarf_Debug, Dwarf_Off);
void		dwarf_dump_info(Dwarf_Debug);
void		dwarf_dump_shstrtab(Dwarf_Debug);
void		dwarf_dump_strtab(Dwarf_Debug);
void		dwarf_dump_symtab(Dwarf_Debug);
void		dwarf_dump_raw(Dwarf_Debug);
void		dwarf_dump_tree(Dwarf_Debug);
Dwarf_Func	dwarf_find_function_by_offset(Dwarf_Debug dbg, Dwarf_Off off);
Dwarf_Func	dwarf_find_function_by_name(Dwarf_Debug dbg, const char *name);
int		dwarf_function_get_addr_range(Dwarf_Func f,
		    Dwarf_Addr *low_pc, Dwarf_Addr *high_pc);
int		dwarf_function_is_inlined(Dwarf_Func f);
void		dwarf_function_iterate_inlined_instance(Dwarf_Func func,
		    Dwarf_Inlined_Callback f, void *data);
int		dwarf_inlined_function_get_addr_range(Dwarf_Inlined_Func f,
		    Dwarf_Addr *low_pc, Dwarf_Addr *high_pc);

__END_DECLS

#endif /* !_LIBDWARF_H_ */


code:
/*-
 * Copyright (c) 2006 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/lib/libelf/libelf.h 210345 2010-07-21 12:14:50Z kaiw $
 */

#ifndef	_LIBELF_H_
#define	_LIBELF_H_

#include <sys/types.h>
#include <sys/elf32.h>
#include <sys/elf64.h>
#include <sys/queue.h>

/* Library private data structures */
typedef struct _Elf Elf;
typedef struct _Elf_Scn Elf_Scn;

/* File types */
typedef enum {
	ELF_K_NONE = 0,
	ELF_K_AR,	/* `ar' archives */
	ELF_K_COFF,	/* COFF files (unsupported) */
	ELF_K_ELF,	/* ELF files */
	ELF_K_NUM
} Elf_Kind;

#define	ELF_K_FIRST	ELF_K_NONE
#define	ELF_K_LAST	ELF_K_NUM

/* Data types */
typedef enum {
	ELF_T_ADDR,
	ELF_T_BYTE,
	ELF_T_CAP,
	ELF_T_DYN,
	ELF_T_EHDR,
	ELF_T_HALF,
	ELF_T_LWORD,
	ELF_T_MOVE,
	ELF_T_MOVEP,
	ELF_T_NOTE,
	ELF_T_OFF,
	ELF_T_PHDR,
	ELF_T_REL,
	ELF_T_RELA,
	ELF_T_SHDR,
	ELF_T_SWORD,
	ELF_T_SXWORD,
	ELF_T_SYMINFO,
	ELF_T_SYM,
	ELF_T_VDEF,
	ELF_T_VNEED,
	ELF_T_WORD,
	ELF_T_XWORD,
	ELF_T_GNUHASH,	/* GNU style hash tables. */
	ELF_T_NUM
} Elf_Type;

#define	ELF_T_FIRST	ELF_T_ADDR
#define	ELF_T_LAST	ELF_T_GNUHASH

/* Commands */
typedef enum {
	ELF_C_NULL = 0,
	ELF_C_CLR,
	ELF_C_FDDONE,
	ELF_C_FDREAD,
	ELF_C_RDWR,
	ELF_C_READ,
	ELF_C_SET,
	ELF_C_WRITE,
	ELF_C_NUM
} Elf_Cmd;

#define	ELF_C_FIRST	ELF_C_NULL
#define	ELF_C_LAST	ELF_C_NUM

/*
 * An `Elf_Data' structure describes data in an
 * ELF section.
 */
typedef struct _Elf_Data {
	/*
	 * `Public' members that are part of the ELF(3) API.
	 */
	uint64_t	d_align;
	void		*d_buf;
	uint64_t	d_off;
	uint64_t	d_size;
	Elf_Type	d_type;
	unsigned int	d_version;

	/*
	 * Members that are not part of the public API.
	 */
	Elf_Scn		*d_scn;		/* containing section */
	unsigned int	d_flags;
	STAILQ_ENTRY(_Elf_Data)	d_next;
} Elf_Data;

/*
 * An `Elf_Arhdr' structure describes an archive
 * header.
 */
typedef struct {
	time_t		ar_date;
	char		*ar_name;	/* archive member name */
	gid_t		ar_gid;
	mode_t		ar_mode;
	char		*ar_rawname;	/* 'raw' member name */
	size_t		ar_size;
	uid_t		ar_uid;
} Elf_Arhdr;

/*
 * An `Elf_Arsym' describes an entry in the archive
 * symbol table.
 */
typedef struct {
	off_t		as_off;		/* byte offset to member's header */
	unsigned long	as_hash;	/* elf_hash() value for name */
	char		*as_name; 	/* null terminated symbol name */
} Elf_Arsym;

/*
 * Error numbers.
 */

enum Elf_Error {
	ELF_E_NONE,	/* No error */
	ELF_E_ARCHIVE,	/* Malformed ar(1) archive */
	ELF_E_ARGUMENT,	/* Invalid argument */
	ELF_E_CLASS,	/* Mismatched ELF class */
	ELF_E_DATA,	/* Invalid data descriptor */
	ELF_E_HEADER,	/* Missing or malformed ELF header */
	ELF_E_IO,	/* I/O error */
	ELF_E_LAYOUT,	/* Layout constraint violation */
	ELF_E_MODE,	/* Wrong mode for ELF descriptor */
	ELF_E_RANGE,	/* Value out of range */
	ELF_E_RESOURCE,	/* Resource exhaustion */
	ELF_E_SECTION,	/* Invalid section descriptor */
	ELF_E_SEQUENCE,	/* API calls out of sequence */
	ELF_E_UNIMPL,	/* Feature is unimplemented */
	ELF_E_VERSION,	/* Unknown API version */
	ELF_E_NUM	/* Max error number */
};

/*
 * Flags defined by the API.
 */

#define	ELF_F_LAYOUT	0x001U	/* application will layout the file */
#define	ELF_F_DIRTY	0x002U	/* a section or ELF file is dirty */

__BEGIN_DECLS
Elf		*elf_begin(int _fd, Elf_Cmd _cmd, Elf *_elf);
int		elf_cntl(Elf *_elf, Elf_Cmd _cmd);
int		elf_end(Elf *_elf);
const char	*elf_errmsg(int _error);
int		elf_errno(void);
void		elf_fill(int _fill);
unsigned int	elf_flagdata(Elf_Data *_data, Elf_Cmd _cmd, unsigned int _flags);
unsigned int	elf_flagehdr(Elf *_elf, Elf_Cmd _cmd, unsigned int _flags);
unsigned int	elf_flagelf(Elf *_elf, Elf_Cmd _cmd, unsigned int _flags);
unsigned int	elf_flagphdr(Elf *_elf, Elf_Cmd _cmd, unsigned int _flags);
unsigned int	elf_flagscn(Elf_Scn *_scn, Elf_Cmd _cmd, unsigned int _flags);
unsigned int	elf_flagshdr(Elf_Scn *_scn, Elf_Cmd _cmd, unsigned int _flags);
Elf_Arhdr	*elf_getarhdr(Elf *_elf);
Elf_Arsym	*elf_getarsym(Elf *_elf, size_t *_ptr);
off_t		elf_getbase(Elf *_elf);
Elf_Data	*elf_getdata(Elf_Scn *, Elf_Data *);
char		*elf_getident(Elf *_elf, size_t *_ptr);
int		elf_getphdrnum(Elf *_elf, size_t *_dst);
int		elf_getphnum(Elf *_elf, size_t *_dst);	/* Deprecated */
Elf_Scn		*elf_getscn(Elf *_elf, size_t _index);
int		elf_getshdrnum(Elf *_elf, size_t *_dst);
int		elf_getshnum(Elf *_elf, size_t *_dst);	/* Deprecated */
int		elf_getshdrstrndx(Elf *_elf, size_t *_dst);
int		elf_getshstrndx(Elf *_elf, size_t *_dst); /* Deprecated */
unsigned long	elf_hash(const char *_name);
Elf_Kind	elf_kind(Elf *_elf);
Elf		*elf_memory(char *_image, size_t _size);
size_t		elf_ndxscn(Elf_Scn *_scn);
Elf_Data	*elf_newdata(Elf_Scn *_scn);
Elf_Scn		*elf_newscn(Elf *_elf);
Elf_Scn		*elf_nextscn(Elf *_elf, Elf_Scn *_scn);
Elf_Cmd		elf_next(Elf *_elf);
off_t		elf_rand(Elf *_elf, off_t _off);
Elf_Data	*elf_rawdata(Elf_Scn *_scn, Elf_Data *_data);
char		*elf_rawfile(Elf *_elf, size_t *_size);
int		elf_setshstrndx(Elf *_elf, size_t _shnum);
char		*elf_strptr(Elf *_elf, size_t _section, size_t _offset);
off_t		elf_update(Elf *_elf, Elf_Cmd _cmd);
unsigned int	elf_version(unsigned int _version);

long		elf32_checksum(Elf *_elf);
size_t		elf32_fsize(Elf_Type _type, size_t _count,
			unsigned int _version);
Elf32_Ehdr	*elf32_getehdr(Elf *_elf);
Elf32_Phdr	*elf32_getphdr(Elf *_elf);
Elf32_Shdr	*elf32_getshdr(Elf_Scn *_scn);
Elf32_Ehdr	*elf32_newehdr(Elf *_elf);
Elf32_Phdr	*elf32_newphdr(Elf *_elf, size_t _count);
Elf_Data	*elf32_xlatetof(Elf_Data *_dst, const Elf_Data *_src,
			unsigned int _enc);
Elf_Data	*elf32_xlatetom(Elf_Data *_dst, const Elf_Data *_src,
			unsigned int _enc);

long		elf64_checksum(Elf *_elf);
size_t		elf64_fsize(Elf_Type _type, size_t _count,
			unsigned int _version);
Elf64_Ehdr	*elf64_getehdr(Elf *_elf);
Elf64_Phdr	*elf64_getphdr(Elf *_elf);
Elf64_Shdr	*elf64_getshdr(Elf_Scn *_scn);
Elf64_Ehdr	*elf64_newehdr(Elf *_elf);
Elf64_Phdr	*elf64_newphdr(Elf *_elf, size_t _count);
Elf_Data	*elf64_xlatetof(Elf_Data *_dst, const Elf_Data *_src,
			unsigned int _enc);
Elf_Data	*elf64_xlatetom(Elf_Data *_dst, const Elf_Data *_src,
			unsigned int _enc);

#if	defined(LIBELF_TEST_HOOKS)
int		_libelf_get_elf_class(Elf *_elf);
int		_libelf_get_max_error(void);
const char	*_libelf_get_no_error_message(void);
const char	*_libelf_get_unknown_error_message(void);
void		_libelf_set_elf_class(Elf *_elf, int _class);
void		_libelf_set_error(int _error);
#endif	/* LIBELF_TEST_HOOKS */
__END_DECLS

#endif	/* _LIBELF_H_ */


code:
/*	$OpenBSD: libgen.h,v 1.4 1999/05/28 22:00:22 espie Exp $	*/
/*	$FreeBSD: release/9.0.0/include/libgen.h 197804 2009-10-06 14:05:57Z rwatson $	*/

/*
 * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _LIBGEN_H_
#define _LIBGEN_H_

#include <sys/cdefs.h>

__BEGIN_DECLS

char	*basename(const char *);
char	*basename_r(const char *, char *);
char	*dirname(const char *);
#if 0
char	*regcmp(const char *, ...);
char	*regex(const char *, const char *, ...);

extern char *__loc1;
#endif

__END_DECLS

#endif /* _LIBGEN_H_ */


code:
/*-
 * Copyright (c) 2003 Poul-Henning Kamp
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The names of the authors may not be used to endorse or promote
 *    products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/lib/libgeom/libgeom.h 202454 2010-01-17 06:20:30Z delphij $
 */
#ifndef _LIBGEOM_H_
#define _LIBGEOM_H_

#include <sys/cdefs.h>

#include <sys/queue.h>
#include <sys/time.h>

#include <geom/geom_ctl.h>

__BEGIN_DECLS

void geom_stats_close(void);
void geom_stats_resync(void);
int geom_stats_open(void);
void *geom_stats_snapshot_get(void);
void geom_stats_snapshot_free(void *);
void geom_stats_snapshot_timestamp(void *, struct timespec *);
void geom_stats_snapshot_reset(void *);
struct devstat *geom_stats_snapshot_next(void *);

char *geom_getxml(void);

/* geom_xml2tree.c */

/*
 * These structs are used to build the tree based on the XML.
 * they're named as the kernel variant without the first '_'.
 */

struct gclass;
struct ggeom;
struct gconsumer;
struct gprovider;

LIST_HEAD(gconf, gconfig);

struct gident {
	void			*lg_id;
	void			*lg_ptr;
	enum {	ISCLASS,
		ISGEOM,
		ISPROVIDER,
		ISCONSUMER }	lg_what;
};

struct gmesh {
	LIST_HEAD(, gclass)	lg_class;
	struct gident		*lg_ident;
};

struct gconfig {
	LIST_ENTRY(gconfig)	lg_config;
	char			*lg_name;
	char			*lg_val;
};

struct gclass {
	void			*lg_id;
	char			*lg_name;
	LIST_ENTRY(gclass)	lg_class;
	LIST_HEAD(, ggeom)	lg_geom;
	struct gconf		lg_config;
};

struct ggeom {
	void			*lg_id;
	struct gclass		*lg_class;
	char			*lg_name;
	u_int			lg_rank;
	LIST_ENTRY(ggeom)	lg_geom;
	LIST_HEAD(, gconsumer)	lg_consumer;
	LIST_HEAD(, gprovider)	lg_provider;
	struct gconf		lg_config;
};

struct gconsumer {
	void			*lg_id;
	struct ggeom		*lg_geom;
	LIST_ENTRY(gconsumer)	lg_consumer;
	struct gprovider	*lg_provider;
	LIST_ENTRY(gconsumer)	lg_consumers;
	char			*lg_mode;
	struct gconf		lg_config;
};

struct gprovider {
	void			*lg_id;
	char			*lg_name;
	struct ggeom		*lg_geom;
	LIST_ENTRY(gprovider)	lg_provider;
	LIST_HEAD(, gconsumer)	lg_consumers;
	char			*lg_mode;
	off_t			lg_mediasize;
	u_int			lg_sectorsize;
	off_t			lg_stripeoffset;
	off_t			lg_stripesize;
	struct gconf		lg_config;
};

struct gident * geom_lookupid(struct gmesh *, const void *);
int geom_xml2tree(struct gmesh *, char *);
int geom_gettree(struct gmesh *);
void geom_deletetree(struct gmesh *);

/* geom_ctl.c */

struct gctl_req;

#ifdef _STDIO_H_			/* limit #include pollution */
void gctl_dump(struct gctl_req *, FILE *);
#endif
void gctl_free(struct gctl_req *);
struct gctl_req *gctl_get_handle(void);
const char *gctl_issue(struct gctl_req *);
void gctl_ro_param(struct gctl_req *, const char *, int, const void *);
void gctl_rw_param(struct gctl_req *, const char *, int, void *);

/* geom_util.c */
int g_open(const char *, int);
int g_close(int);
off_t g_mediasize(int);
ssize_t g_sectorsize(int);
off_t g_stripeoffset(int);
off_t g_stripesize(int);
int g_flush(int);
int g_delete(int, off_t, off_t);
int g_get_ident(int, char *, size_t);
int g_get_name(const char *, char *, size_t);
int g_open_by_ident(const char *, int, char *, size_t);
char *g_device_path(const char *);
char *g_providername(int);

__END_DECLS

#endif /* _LIBGEOM_H_ */


code:
/*
 * Copyright (c) 1999-2004, 2006, 2008 Sendmail, Inc. and its suppliers.
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 *
 *
 *	$Id: mfapi.h,v 8.80 2009/11/06 00:57:08 ca Exp $
 */

/*
**  MFAPI.H -- Global definitions for mail filter library and mail filters.
*/

#ifndef _LIBMILTER_MFAPI_H
# define _LIBMILTER_MFAPI_H	1

#ifndef SMFI_VERSION
# if _FFR_MDS_NEGOTIATE
#  define SMFI_VERSION	0x01000002	/* libmilter version number */

   /* first libmilter version that has MDS support */
#  define SMFI_VERSION_MDS	0x01000002
# else /* _FFR_MDS_NEGOTIATE */
#  define SMFI_VERSION	0x01000001	/* libmilter version number */
# endif /* _FFR_MDS_NEGOTIATE */
#endif /* ! SMFI_VERSION */

#define SM_LM_VRS_MAJOR(v)	(((v) & 0x7f000000) >> 24)
#define SM_LM_VRS_MINOR(v)	(((v) & 0x007fff00) >> 8)
#define SM_LM_VRS_PLVL(v)	((v) & 0x0000007f)

# include <sys/types.h>
# include <sys/socket.h>

#include "libmilter/mfdef.h"

# define LIBMILTER_API		extern

/* Only need to export C interface if used by C++ source code */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#ifndef _SOCK_ADDR
# define _SOCK_ADDR	struct sockaddr
#endif /* ! _SOCK_ADDR */

/*
**  libmilter functions return one of the following to indicate
**  success/failure(/continue):
*/

#define MI_SUCCESS	0
#define MI_FAILURE	(-1)
#if _FFR_WORKERS_POOL
# define MI_CONTINUE	1
#endif /* _FFR_WORKERS_POOL */

/* "forward" declarations */
typedef struct smfi_str SMFICTX;
typedef struct smfi_str *SMFICTX_PTR;

typedef struct smfiDesc smfiDesc_str;
typedef struct smfiDesc	*smfiDesc_ptr;

/*
**  Type which callbacks should return to indicate message status.
**  This may take on one of the SMFIS_* values listed below.
*/

typedef int	sfsistat;

#if defined(__linux__) && defined(__GNUC__) && defined(__cplusplus) && __GNUC_MINOR__ >= 8
# define SM__P(X)	__PMT(X)
#else /* __linux__ && __GNUC__ && __cplusplus && _GNUC_MINOR__ >= 8 */
# define SM__P(X)	__P(X)
#endif /* __linux__ && __GNUC__ && __cplusplus && _GNUC_MINOR__ >= 8 */

/* Some platforms don't define __P -- do it for them here: */
#ifndef __P
# ifdef __STDC__
#  define __P(X) X
# else /* __STDC__ */
#  define __P(X) ()
# endif /* __STDC__ */
#endif /* __P */

#if SM_CONF_STDBOOL_H
# include <stdbool.h>
#else /* SM_CONF_STDBOOL_H */
# ifndef __cplusplus
#  ifndef bool
#   ifndef __bool_true_false_are_defined
typedef int	bool;
#    define __bool_true_false_are_defined	1
#   endif /* ! __bool_true_false_are_defined */
#  endif /* bool */
# endif /* ! __cplusplus */
#endif /* SM_CONF_STDBOOL_H */

/*
**  structure describing one milter
*/

struct smfiDesc
{
	char		*xxfi_name;	/* filter name */
	int		xxfi_version;	/* version code -- do not change */
	unsigned long	xxfi_flags;	/* flags */

	/* connection info filter */
	sfsistat	(*xxfi_connect) SM__P((SMFICTX *, char *, _SOCK_ADDR *));

	/* SMTP HELO command filter */
	sfsistat	(*xxfi_helo) SM__P((SMFICTX *, char *));

	/* envelope sender filter */
	sfsistat	(*xxfi_envfrom) SM__P((SMFICTX *, char **));

	/* envelope recipient filter */
	sfsistat	(*xxfi_envrcpt) SM__P((SMFICTX *, char **));

	/* header filter */
	sfsistat	(*xxfi_header) SM__P((SMFICTX *, char *, char *));

	/* end of header */
	sfsistat	(*xxfi_eoh) SM__P((SMFICTX *));

	/* body block */
	sfsistat	(*xxfi_body) SM__P((SMFICTX *, unsigned char *, size_t));

	/* end of message */
	sfsistat	(*xxfi_eom) SM__P((SMFICTX *));

	/* message aborted */
	sfsistat	(*xxfi_abort) SM__P((SMFICTX *));

	/* connection cleanup */
	sfsistat	(*xxfi_close) SM__P((SMFICTX *));

	/* any unrecognized or unimplemented command filter */
	sfsistat	(*xxfi_unknown) SM__P((SMFICTX *, const char *));

	/* SMTP DATA command filter */
	sfsistat	(*xxfi_data) SM__P((SMFICTX *));

	/* negotiation callback */
	sfsistat	(*xxfi_negotiate) SM__P((SMFICTX *,
					unsigned long, unsigned long,
					unsigned long, unsigned long,
					unsigned long *, unsigned long *,
					unsigned long *, unsigned long *));

#if 0
	/* signal handler callback, not yet implemented. */
	int		(*xxfi_signal) SM__P((int));
#endif

};

LIBMILTER_API int smfi_opensocket __P((bool));
LIBMILTER_API int smfi_register __P((struct smfiDesc));
LIBMILTER_API int smfi_main __P((void));
LIBMILTER_API int smfi_setbacklog __P((int));
LIBMILTER_API int smfi_setdbg __P((int));
LIBMILTER_API int smfi_settimeout __P((int));
LIBMILTER_API int smfi_setconn __P((char *));
LIBMILTER_API int smfi_stop __P((void));
LIBMILTER_API size_t smfi_setmaxdatasize __P((size_t));
LIBMILTER_API int smfi_version __P((unsigned int *, unsigned int *, unsigned int *));

/*
**  What the filter might do -- values to be ORed together for
**  smfiDesc.xxfi_flags.
*/

#define SMFIF_NONE	0x00000000L	/* no flags */
#define SMFIF_ADDHDRS	0x00000001L	/* filter may add headers */
#define SMFIF_CHGBODY	0x00000002L	/* filter may replace body */
#define SMFIF_MODBODY	SMFIF_CHGBODY	/* backwards compatible */
#define SMFIF_ADDRCPT	0x00000004L	/* filter may add recipients */
#define SMFIF_DELRCPT	0x00000008L	/* filter may delete recipients */
#define SMFIF_CHGHDRS	0x00000010L	/* filter may change/delete headers */
#define SMFIF_QUARANTINE 0x00000020L	/* filter may quarantine envelope */

/* filter may change "from" (envelope sender) */
#define SMFIF_CHGFROM	0x00000040L
#define SMFIF_ADDRCPT_PAR	0x00000080L	/* add recipients incl. args */

/* filter can send set of symbols (macros) that it wants */
#define SMFIF_SETSYMLIST	0x00000100L

/*
**  Macro "places";
**  Notes:
**  - must be coordinated with libmilter/engine.c and sendmail/milter.c
**  - the order MUST NOT be changed as it would break compatibility between
**	different versions. It's ok to append new entries however
**	(hence the list is not sorted by the SMT protocol steps).
*/

#define SMFIM_FIRST	0	/* Do NOT use, internal marker only */
#define SMFIM_CONNECT	0	/* connect */
#define SMFIM_HELO	1	/* HELO/EHLO */
#define SMFIM_ENVFROM	2	/* MAIL From */
#define SMFIM_ENVRCPT	3	/* RCPT To */
#define SMFIM_DATA	4	/* DATA */
#define SMFIM_EOM	5	/* end of message (final dot) */
#define SMFIM_EOH	6	/* end of header */
#define SMFIM_LAST	6	/* Do NOT use, internal marker only */

/*
**  Continue processing message/connection.
*/

#define SMFIS_CONTINUE	0

/*
**  Reject the message/connection.
**  No further routines will be called for this message
**  (or connection, if returned from a connection-oriented routine).
*/

#define SMFIS_REJECT	1

/*
**  Accept the message,
**  but silently discard the message.
**  No further routines will be called for this message.
**  This is only meaningful from message-oriented routines.
*/

#define SMFIS_DISCARD	2

/*
**  Accept the message/connection.
**  No further routines will be called for this message
**  (or connection, if returned from a connection-oriented routine;
**  in this case, it causes all messages on this connection
**  to be accepted without filtering).
*/

#define SMFIS_ACCEPT	3

/*
**  Return a temporary failure, i.e.,
**  the corresponding SMTP command will return a 4xx status code.
**  In some cases this may prevent further routines from
**  being called on this message or connection,
**  although in other cases (e.g., when processing an envelope
**  recipient) processing of the message will continue.
*/

#define SMFIS_TEMPFAIL	4

/*
**  Do not send a reply to the MTA
*/

#define SMFIS_NOREPLY	7

/*
**  Skip over rest of same callbacks, e.g., body.
*/

#define SMFIS_SKIP	8

/* xxfi_negotiate: use all existing protocol options/actions */
#define SMFIS_ALL_OPTS	10

#if 0
/*
**  Filter Routine Details
*/

/* connection info filter */
extern sfsistat	xxfi_connect __P((SMFICTX *, char *, _SOCK_ADDR *));

/*
**  xxfi_connect(ctx, hostname, hostaddr) Invoked on each connection
**
**	char *hostname; Host domain name, as determined by a reverse lookup
**		on the host address.
**	_SOCK_ADDR *hostaddr; Host address, as determined by a getpeername
**		call on the SMTP socket.
*/

/* SMTP HELO command filter */
extern sfsistat	xxfi_helo __P((SMFICTX *, char *));

/*
**  xxfi_helo(ctx, helohost) Invoked on SMTP HELO/EHLO command
**
**	char *helohost; Value passed to HELO/EHLO command, which should be
**		the domain name of the sending host (but is, in practice,
**		anything the sending host wants to send).
*/

/* envelope sender filter */
extern sfsistat	xxfi_envfrom __P((SMFICTX *, char **));

/*
**  xxfi_envfrom(ctx, argv) Invoked on envelope from
**
**	char **argv; Null-terminated SMTP command arguments;
**		argv[0] is guaranteed to be the sender address.
**		Later arguments are the ESMTP arguments.
*/

/* envelope recipient filter */
extern sfsistat	xxfi_envrcpt __P((SMFICTX *, char **));

/*
**  xxfi_envrcpt(ctx, argv) Invoked on each envelope recipient
**
**	char **argv; Null-terminated SMTP command arguments;
**		argv[0] is guaranteed to be the recipient address.
**		Later arguments are the ESMTP arguments.
*/

/* unknown command filter */

extern sfsistat	*xxfi_unknown __P((SMFICTX *, const char *));

/*
**  xxfi_unknown(ctx, arg) Invoked when SMTP command is not recognized or not
**  implemented.
**	const char *arg; Null-terminated SMTP command
*/

/* header filter */
extern sfsistat	xxfi_header __P((SMFICTX *, char *, char *));

/*
**  xxfi_header(ctx, headerf, headerv) Invoked on each message header. The
**  content of the header may have folded white space (that is, multiple
**  lines with following white space) included.
**
**	char *headerf; Header field name
**	char *headerv; Header field value
*/

/* end of header */
extern sfsistat	xxfi_eoh __P((SMFICTX *));

/*
**  xxfi_eoh(ctx) Invoked at end of header
*/

/* body block */
extern sfsistat	xxfi_body __P((SMFICTX *, unsigned char *, size_t));

/*
**  xxfi_body(ctx, bodyp, bodylen) Invoked for each body chunk. There may
**  be multiple body chunks passed to the filter. End-of-lines are
**  represented as received from SMTP (normally Carriage-Return/Line-Feed).
**
**	unsigned char *bodyp; Pointer to body data
**	size_t bodylen; Length of body data
*/

/* end of message */
extern sfsistat	xxfi_eom __P((SMFICTX *));

/*
**  xxfi_eom(ctx) Invoked at end of message. This routine can perform
**  special operations such as modifying the message header, body, or
**  envelope.
*/

/* message aborted */
extern sfsistat	xxfi_abort __P((SMFICTX *));

/*
**  xxfi_abort(ctx) Invoked if message is aborted outside of the control of
**  the filter, for example, if the SMTP sender issues an RSET command. If
**  xxfi_abort is called, xxfi_eom will not be called and vice versa.
*/

/* connection cleanup */
extern sfsistat	xxfi_close __P((SMFICTX *));

/*
**  xxfi_close(ctx) Invoked at end of the connection. This is called on
**  close even if the previous mail transaction was aborted.
*/
#endif /* 0 */

/*
**  Additional information is passed in to the vendor filter routines using
**  symbols. Symbols correspond closely to sendmail macros. The symbols
**  defined depend on the context. The value of a symbol is accessed using:
*/

/* Return the value of a symbol. */
LIBMILTER_API char * smfi_getsymval __P((SMFICTX *, char *));

/*
**  Return the value of a symbol.
**
**	SMFICTX *ctx; Opaque context structure
**	char *symname; The name of the symbol to access.
*/

/*
**  Vendor filter routines that want to pass additional information back to
**  the MTA for use in SMTP replies may call smfi_setreply before returning.
*/

LIBMILTER_API int smfi_setreply __P((SMFICTX *, char *, char *, char *));

/*
**  Alternatively, smfi_setmlreply can be called if a multi-line SMTP reply
**  is needed.
*/

LIBMILTER_API int smfi_setmlreply __P((SMFICTX *, const char *, const char *, ...));

/*
**  Set the specific reply code to be used in response to the active
**  command. If not specified, a generic reply code is used.
**
**	SMFICTX *ctx; Opaque context structure
**	char *rcode; The three-digit (RFC 821) SMTP reply code to be
**		returned, e.g., ``551''.
**	char *xcode; The extended (RFC 2034) reply code, e.g., ``5.7.6''.
**	char *message; The text part of the SMTP reply.
*/

/*
**  The xxfi_eom routine is called at the end of a message (essentially,
**  after the final DATA dot). This routine can call some special routines
**  to modify the envelope, header, or body of the message before the
**  message is enqueued. These routines must not be called from any vendor
**  routine other than xxfi_eom.
*/

LIBMILTER_API int smfi_addheader __P((SMFICTX *, char *, char *));

/*
**  Add a header to the message. It is not checked for standards
**  compliance; the mail filter must ensure that no protocols are violated
**  as a result of adding this header.
**
**	SMFICTX *ctx; Opaque context structure
**	char *headerf; Header field name
**	char *headerv; Header field value
*/

LIBMILTER_API int smfi_chgheader __P((SMFICTX *, char *, int, char *));

/*
**  Change/delete a header in the message.  It is not checked for standards
**  compliance; the mail filter must ensure that no protocols are violated
**  as a result of adding this header.
**
**	SMFICTX *ctx; Opaque context structure
**	char *headerf; Header field name
**	int index; The Nth occurence of header field name
**	char *headerv; New header field value (empty for delete header)
*/

LIBMILTER_API int smfi_insheader __P((SMFICTX *, int, char *, char *));

/*
**  Insert a header into the message.  It is not checked for standards
**  compliance; the mail filter must ensure that no protocols are violated
**  as a result of adding this header.
**
**	SMFICTX *ctx; Opaque context structure
**  	int idx; index into the header list where the insertion should happen
**	char *headerh; Header field name
**	char *headerv; Header field value
*/

LIBMILTER_API int smfi_chgfrom __P((SMFICTX *, char *, char *));

/*
**  Modify envelope sender address
**
**	SMFICTX *ctx; Opaque context structure
**	char *mail; New envelope sender address
**	char *args; ESMTP arguments
*/

LIBMILTER_API int smfi_addrcpt __P((SMFICTX *, char *));

/*
**  Add a recipient to the envelope
**
**	SMFICTX *ctx; Opaque context structure
**	char *rcpt; Recipient to be added
*/

LIBMILTER_API int smfi_addrcpt_par __P((SMFICTX *, char *, char *));

/*
**  Add a recipient to the envelope
**
**	SMFICTX *ctx; Opaque context structure
**	char *rcpt; Recipient to be added
**	char *args; ESMTP arguments
*/

LIBMILTER_API int smfi_delrcpt __P((SMFICTX *, char *));

/*
**  Send a "no-op" up to the MTA to tell it we're still alive, so long
**  milter-side operations don't time out.
**
**	SMFICTX *ctx; Opaque context structure
*/

LIBMILTER_API int smfi_progress __P((SMFICTX *));

/*
**  Delete a recipient from the envelope
**
**	SMFICTX *ctx; Opaque context structure
**	char *rcpt; Envelope recipient to be deleted. This should be in
**		exactly the form passed to xxfi_envrcpt or the address may
**		not be deleted.
*/

LIBMILTER_API int smfi_replacebody __P((SMFICTX *, unsigned char *, int));

/*
**  Replace the body of the message. This routine may be called multiple
**  times if the body is longer than convenient to send in one call. End of
**  line should be represented as Carriage-Return/Line Feed.
**
**	char *bodyp; Pointer to block of body information to insert
**	int bodylen; Length of data pointed at by bodyp
*/

/*
**  If the message is aborted (for example, if the SMTP sender sends the
**  envelope but then does a QUIT or RSET before the data is sent),
**  xxfi_abort is called. This can be used to reset state.
*/

/*
**  Quarantine an envelope
**
**	SMFICTX *ctx; Opaque context structure
**	char *reason: explanation
*/

LIBMILTER_API int smfi_quarantine __P((SMFICTX *ctx, char *reason));

/*
**  Connection-private data (specific to an SMTP connection) can be
**  allocated using the smfi_setpriv routine; routines can access private
**  data using smfi_getpriv.
*/

LIBMILTER_API int smfi_setpriv __P((SMFICTX *, void *));

/*
**  Set the private data pointer
**
**	SMFICTX *ctx; Opaque context structure
**	void *privatedata; Pointer to private data area
*/

LIBMILTER_API void *smfi_getpriv __P((SMFICTX *));

/*
**  Get the private data pointer
**
**	SMFICTX *ctx; Opaque context structure
**	void *privatedata; Pointer to private data area
*/

LIBMILTER_API int smfi_setsymlist __P((SMFICTX *, int, char *));

/*
**  Set list of symbols (macros) to receive
**
**	SMFICTX *ctx; Opaque context structure
**	int where; where in the SMTP dialogue should the macros be sent
**	char *macros; list of macros (space separated)
*/

#if _FFR_THREAD_MONITOR
LIBMILTER_API int smfi_set_max_exec_time __P((unsigned int));
#endif /* _FFR_THREAD_MONITOR */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* ! _LIBMILTER_MFAPI_H */


code:
/*
 * Copyright (c) 1999-2007 Sendmail, Inc. and its suppliers.
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 *
 *
 *	$Id: mfdef.h,v 8.39 2009/11/06 00:57:08 ca Exp $
 */

/*
**  mfdef.h -- Global definitions for mail filter and MTA.
*/

#ifndef _LIBMILTER_MFDEF_H
# define _LIBMILTER_MFDEF_H	1

#ifndef SMFI_PROT_VERSION
# define SMFI_PROT_VERSION	6	/* MTA - libmilter protocol version */
#endif /* SMFI_PROT_VERSION */

/* Shared protocol constants */
#define MILTER_LEN_BYTES	4	/* length of 32 bit integer in bytes */
#define MILTER_OPTLEN	(MILTER_LEN_BYTES * 3) /* length of options */
#define MILTER_CHUNK_SIZE	65535	/* body chunk size */
#define MILTER_MAX_DATA_SIZE	65535	/* default milter command data limit */

#if _FFR_MDS_NEGOTIATE
# define MILTER_MDS_64K	((64 * 1024) - 1)
# define MILTER_MDS_256K ((256 * 1024) - 1)
# define MILTER_MDS_1M	((1024 * 1024) - 1)
#endif /* _FFR_MDS_NEGOTIATE */

/* These apply to SMFIF_* flags */
#define SMFI_V1_ACTS	0x0000000FL	/* The actions of V1 filter */
#define SMFI_V2_ACTS	0x0000003FL	/* The actions of V2 filter */
#define SMFI_CURR_ACTS	0x000001FFL	/* actions of current version */

/* address families */
#define SMFIA_UNKNOWN		'U'	/* unknown */
#define SMFIA_UNIX		'L'	/* unix/local */
#define SMFIA_INET		'4'	/* inet */
#define SMFIA_INET6		'6'	/* inet6 */

/* commands: don't use anything smaller than ' ' */
#define SMFIC_ABORT		'A'	/* Abort */
#define SMFIC_BODY		'B'	/* Body chunk */
#define SMFIC_CONNECT		'C'	/* Connection information */
#define SMFIC_MACRO		'D'	/* Define macro */
#define SMFIC_BODYEOB		'E'	/* final body chunk (End) */
#define SMFIC_HELO		'H'	/* HELO/EHLO */
#define SMFIC_QUIT_NC		'K'	/* QUIT but new connection follows */
#define SMFIC_HEADER		'L'	/* Header */
#define SMFIC_MAIL		'M'	/* MAIL from */
#define SMFIC_EOH		'N'	/* EOH */
#define SMFIC_OPTNEG		'O'	/* Option negotiation */
#define SMFIC_QUIT		'Q'	/* QUIT */
#define SMFIC_RCPT		'R'	/* RCPT to */
#define SMFIC_DATA		'T'	/* DATA */
#define SMFIC_UNKNOWN		'U'	/* Any unknown command */

/* actions (replies) */
#define SMFIR_ADDRCPT		'+'	/* add recipient */
#define SMFIR_DELRCPT		'-'	/* remove recipient */
#define SMFIR_ADDRCPT_PAR	'2'	/* add recipient (incl. ESMTP args) */
#define SMFIR_SHUTDOWN		'4'	/* 421: shutdown (internal to MTA) */
#define SMFIR_ACCEPT		'a'	/* accept */
#define SMFIR_REPLBODY		'b'	/* replace body (chunk) */
#define SMFIR_CONTINUE		'c'	/* continue */
#define SMFIR_DISCARD		'd'	/* discard */
#define SMFIR_CHGFROM		'e'	/* change envelope sender (from) */
#define SMFIR_CONN_FAIL		'f'	/* cause a connection failure */
#define SMFIR_ADDHEADER		'h'	/* add header */
#define SMFIR_INSHEADER		'i'	/* insert header */
#define SMFIR_SETSYMLIST	'l'	/* set list of symbols (macros) */
#define SMFIR_CHGHEADER		'm'	/* change header */
#define SMFIR_PROGRESS		'p'	/* progress */
#define SMFIR_QUARANTINE	'q'	/* quarantine */
#define SMFIR_REJECT		'r'	/* reject */
#define SMFIR_SKIP		's'	/* skip */
#define SMFIR_TEMPFAIL		't'	/* tempfail */
#define SMFIR_REPLYCODE		'y'	/* reply code etc */

/* What the MTA can send/filter wants in protocol */
#define SMFIP_NOCONNECT 0x00000001L	/* MTA should not send connect info */
#define SMFIP_NOHELO	0x00000002L	/* MTA should not send HELO info */
#define SMFIP_NOMAIL	0x00000004L	/* MTA should not send MAIL info */
#define SMFIP_NORCPT	0x00000008L	/* MTA should not send RCPT info */
#define SMFIP_NOBODY	0x00000010L	/* MTA should not send body */
#define SMFIP_NOHDRS	0x00000020L	/* MTA should not send headers */
#define SMFIP_NOEOH	0x00000040L	/* MTA should not send EOH */
#define SMFIP_NR_HDR	0x00000080L	/* No reply for headers */
#define SMFIP_NOHREPL	SMFIP_NR_HDR	/* No reply for headers */
#define SMFIP_NOUNKNOWN 0x00000100L /* MTA should not send unknown commands */
#define SMFIP_NODATA    0x00000200L	/* MTA should not send DATA */
#define SMFIP_SKIP	0x00000400L	/* MTA understands SMFIS_SKIP */
#define SMFIP_RCPT_REJ	0x00000800L /* MTA should also send rejected RCPTs */
#define SMFIP_NR_CONN	0x00001000L	/* No reply for connect */
#define SMFIP_NR_HELO	0x00002000L	/* No reply for HELO */
#define SMFIP_NR_MAIL	0x00004000L	/* No reply for MAIL */
#define SMFIP_NR_RCPT	0x00008000L	/* No reply for RCPT */
#define SMFIP_NR_DATA	0x00010000L	/* No reply for DATA */
#define SMFIP_NR_UNKN	0x00020000L	/* No reply for UNKN */
#define SMFIP_NR_EOH	0x00040000L	/* No reply for eoh */
#define SMFIP_NR_BODY	0x00080000L	/* No reply for body chunk */
#define SMFIP_HDR_LEADSPC 0x00100000L	/* header value leading space */
#define SMFIP_MDS_256K	0x10000000L	/* MILTER_MAX_DATA_SIZE=256K */
#define SMFIP_MDS_1M	0x20000000L	/* MILTER_MAX_DATA_SIZE=1M */
/* #define SMFIP_	0x40000000L	reserved: see SMFI_INTERNAL*/

#define SMFI_V1_PROT	0x0000003FL	/* The protocol of V1 filter */
#define SMFI_V2_PROT	0x0000007FL	/* The protocol of V2 filter */

/* all defined protocol bits */
#define SMFI_CURR_PROT	0x001FFFFFL

/* internal flags: only used between MTA and libmilter */
#define SMFI_INTERNAL	0x70000000L

#if _FFR_MILTER_CHECK
# define SMFIP_TEST	0x80000000L
#endif /* _FFR_MILTER_CHECK */

#endif /* !_LIBMILTER_MFDEF_H */


code:
/*-
 * Copyright (c) 2010 The FreeBSD Foundation
 * Copyright (c) 2008 John Birrell (jb@freebsd.org)
 * All rights reserved.
 *
 * Portions of this software were developed by Rui Paulo under sponsorship
 * from the FreeBSD Foundation.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/lib/libproc/libproc.h 211184 2010-08-11 17:33:26Z rpaulo $
 */

#ifndef	_LIBPROC_H_
#define	_LIBPROC_H_

#include <gelf.h>
#include <rtld_db.h>
#include <limits.h>

struct proc_handle;

typedef void (*proc_child_func)(void *);

/* Values returned by proc_state(). */
#define PS_IDLE		1
#define PS_STOP		2
#define PS_RUN		3
#define PS_UNDEAD	4
#define PS_DEAD		5
#define PS_LOST		6

/* Reason values for proc_detach(). */
#define PRELEASE_HANG	1
#define PRELEASE_KILL	2

typedef struct prmap {
	uintptr_t	pr_vaddr;	/* Virtual address. */
	size_t		pr_size;	/* Mapping size in bytes */
	size_t		pr_offset;	/* Mapping offset in object */
	char		pr_mapname[PATH_MAX];	/* Mapping filename */
	uint8_t		pr_mflags;	/* Protection flags */
#define	MA_READ		0x01
#define	MA_WRITE	0x02
#define	MA_EXEC		0x04
#define	MA_COW		0x08
#define MA_NEEDS_COPY	0x10
#define	MA_NOCOREDUMP	0x20
} prmap_t;

typedef int proc_map_f(void *, const prmap_t *, const char *);
typedef int proc_sym_f(void *, const GElf_Sym *, const char *);

/* Values for ELF sections */
#define	PR_SYMTAB	1
#define PR_DYNSYM	2

/* Values for the 'mask' parameter in the iteration functions */
#define	BIND_LOCAL	0x0001
#define BIND_GLOBAL	0x0002
#define BIND_WEAK	0x0004
#define BIND_ANY	(BIND_LOCAL|BIND_GLOBAL|BIND_WEAK)
#define TYPE_NOTYPE	0x0100
#define TYPE_OBJECT	0x0200
#define TYPE_FUNC	0x0400
#define TYPE_SECTION	0x0800
#define TYPE_FILE	0x1000
#define TYPE_ANY	(TYPE_NOTYPE|TYPE_OBJECT|TYPE_FUNC|TYPE_SECTION|\
    			 TYPE_FILE)

typedef enum {
	REG_PC,
	REG_SP,
	REG_RVAL1,
	REG_RVAL2
} proc_reg_t;

#define SIG2STR_MAX	8

typedef struct lwpstatus {
	int pr_why;
#define PR_REQUESTED	1
#define PR_FAULTED	2
#define PR_SYSENTRY	3
#define PR_SYSEXIT	4
	int pr_what;
#define FLTBPT		-1
} lwpstatus_t;

/* Function prototype definitions. */
__BEGIN_DECLS

prmap_t *proc_addr2map(struct proc_handle *, uintptr_t);
prmap_t *proc_name2map(struct proc_handle *, const char *);
char	*proc_objname(struct proc_handle *, uintptr_t, char *, size_t);
prmap_t *proc_obj2map(struct proc_handle *, const char *);
int	proc_iter_objs(struct proc_handle *, proc_map_f *, void *);
int	proc_iter_symbyaddr(struct proc_handle *, const char *, int,
	     int, proc_sym_f *, void *);
int	proc_addr2sym(struct proc_handle *, uintptr_t, char *, size_t, GElf_Sym *);
int	proc_attach(pid_t pid, int flags, struct proc_handle **pphdl);
int	proc_continue(struct proc_handle *);
int	proc_clearflags(struct proc_handle *, int);
int	proc_create(const char *, char * const *, proc_child_func *, void *,
	    struct proc_handle **);
int	proc_detach(struct proc_handle *, int);
int	proc_getflags(struct proc_handle *);
int	proc_name2sym(struct proc_handle *, const char *, const char *, GElf_Sym *);
int	proc_setflags(struct proc_handle *, int);
int	proc_state(struct proc_handle *);
pid_t	proc_getpid(struct proc_handle *);
int	proc_wstatus(struct proc_handle *);
int	proc_getwstat(struct proc_handle *);
char *	proc_signame(int, char *, size_t);
int	proc_read(struct proc_handle *, void *, size_t, size_t);
const lwpstatus_t *
	proc_getlwpstatus(struct proc_handle *);
void	proc_free(struct proc_handle *);
rd_agent_t *proc_rdagent(struct proc_handle *);
void	proc_updatesyms(struct proc_handle *);
int	proc_bkptset(struct proc_handle *, uintptr_t, unsigned long *);
int	proc_bkptdel(struct proc_handle *, uintptr_t, unsigned long);
void	proc_bkptregadj(unsigned long *);
int	proc_bkptexec(struct proc_handle *, unsigned long);
int	proc_regget(struct proc_handle *, proc_reg_t, unsigned long *);
int	proc_regset(struct proc_handle *, proc_reg_t, unsigned long);

__END_DECLS

#endif /* !_LIBPROC_H_ */


code:
/*-
 * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/lib/libprocstat/libprocstat.h 224859 2011-08-14 00:42:09Z rwatson $
 */

#ifndef _LIBPROCSTAT_H_
#define	_LIBPROCSTAT_H_

/*
 * Vnode types.
 */
#define	PS_FST_VTYPE_VNON	1
#define	PS_FST_VTYPE_VREG	2
#define	PS_FST_VTYPE_VDIR	3
#define	PS_FST_VTYPE_VBLK	4
#define	PS_FST_VTYPE_VCHR	5
#define	PS_FST_VTYPE_VLNK	6
#define	PS_FST_VTYPE_VSOCK	7
#define	PS_FST_VTYPE_VFIFO	8
#define	PS_FST_VTYPE_VBAD	9
#define	PS_FST_VTYPE_UNKNOWN	255

/*
 * Descriptor types.
 */
#define	PS_FST_TYPE_VNODE	1
#define	PS_FST_TYPE_FIFO	2
#define	PS_FST_TYPE_SOCKET	3
#define	PS_FST_TYPE_PIPE	4
#define	PS_FST_TYPE_PTS		5
#define	PS_FST_TYPE_KQUEUE	6
#define	PS_FST_TYPE_CRYPTO	7
#define	PS_FST_TYPE_MQUEUE	8
#define	PS_FST_TYPE_SHM		9
#define	PS_FST_TYPE_SEM		10
#define	PS_FST_TYPE_UNKNOWN	11
#define	PS_FST_TYPE_NONE	12

/*
 * Special descriptor numbers.
 */
#define	PS_FST_UFLAG_RDIR	0x0001
#define	PS_FST_UFLAG_CDIR	0x0002
#define	PS_FST_UFLAG_JAIL	0x0004
#define	PS_FST_UFLAG_TRACE	0x0008
#define	PS_FST_UFLAG_TEXT	0x0010
#define	PS_FST_UFLAG_MMAP	0x0020
#define	PS_FST_UFLAG_CTTY	0x0040

/*
 * Descriptor flags.
 */
#define PS_FST_FFLAG_READ	0x0001
#define PS_FST_FFLAG_WRITE	0x0002
#define	PS_FST_FFLAG_NONBLOCK	0x0004
#define	PS_FST_FFLAG_APPEND	0x0008
#define	PS_FST_FFLAG_SHLOCK	0x0010
#define	PS_FST_FFLAG_EXLOCK	0x0020
#define	PS_FST_FFLAG_ASYNC	0x0040
#define	PS_FST_FFLAG_SYNC	0x0080
#define	PS_FST_FFLAG_NOFOLLOW	0x0100
#define	PS_FST_FFLAG_CREAT	0x0200
#define	PS_FST_FFLAG_TRUNC	0x0400
#define	PS_FST_FFLAG_EXCL	0x0800
#define	PS_FST_FFLAG_DIRECT	0x1000
#define	PS_FST_FFLAG_EXEC	0x2000
#define	PS_FST_FFLAG_HASLOCK	0x4000
#define	PS_FST_FFLAG_CAPABILITY	0x8000

struct procstat;
struct filestat {
	int	fs_type;	/* Descriptor type. */
	int	fs_flags;	/* filestat specific flags. */
	int	fs_fflags;	/* Descriptor access flags. */
	int	fs_uflags;	/* How this file is used. */
	int	fs_fd;		/* File descriptor number. */
	int	fs_ref_count;	/* Reference count. */
	off_t	fs_offset;	/* Seek location. */
	void	*fs_typedep;	/* Type dependent data. */
	char	*fs_path;
	STAILQ_ENTRY(filestat)	next;
	cap_rights_t	fs_cap_rights;	/* Capability rights, if flag set. */
};
struct vnstat {
	uint64_t	vn_fileid;
	uint64_t	vn_size;
	char		*vn_mntdir;
	uint32_t	vn_dev;
	uint32_t	vn_fsid;
	int		vn_type;
	uint16_t	vn_mode;
	char		vn_devname[SPECNAMELEN + 1];
};
struct ptsstat {
	uint32_t	dev;
	char		devname[SPECNAMELEN + 1];
};
struct pipestat {
	size_t		buffer_cnt;
	uint64_t	addr;
	uint64_t	peer;
};
struct sockstat {
	uint64_t	inp_ppcb;
	uint64_t	so_addr;
	uint64_t	so_pcb;
	uint64_t	unp_conn;
	int		dom_family;
	int		proto;
	int		so_rcv_sb_state;
	int		so_snd_sb_state;
	struct sockaddr_storage	sa_local;	/* Socket address. */
	struct sockaddr_storage	sa_peer;	/* Peer address. */
	int		type;
	char		dname[32];
};

STAILQ_HEAD(filestat_list, filestat);

void	procstat_close(struct procstat *procstat);
void	procstat_freeprocs(struct procstat *procstat, struct kinfo_proc *p);
void	procstat_freefiles(struct procstat *procstat,
    struct filestat_list *head);
struct filestat_list	*procstat_getfiles(struct procstat *procstat,
    struct kinfo_proc *kp, int mmapped);
struct kinfo_proc	*procstat_getprocs(struct procstat *procstat,
    int what, int arg, unsigned int *count);
int	procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst,
    struct pipestat *pipe, char *errbuf);
int	procstat_get_pts_info(struct procstat *procstat, struct filestat *fst,
    struct ptsstat *pts, char *errbuf);
int	procstat_get_socket_info(struct procstat *procstat, struct filestat *fst,
    struct sockstat *sock, char *errbuf);
int	procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
    struct vnstat *vn, char *errbuf);
struct procstat	*procstat_open_sysctl(void);
struct procstat	*procstat_open_kvm(const char *nlistf, const char *memf);

#endif	/* !_LIBPROCSTAT_H_ */


code:
/*
 * Copyright (c) 2002 Juli Mallett.  All rights reserved.
 *
 * This software was written by Juli Mallett <jmallett@FreeBSD.org> for the
 * FreeBSD project.  Redistribution and use in source and binary forms, with
 * or without modification, are permitted provided that the following
 * conditions are met:
 *
 * 1. Redistribution of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistribution in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/lib/libufs/libufs.h 218601 2011-02-12 12:46:00Z kib $
 */

#ifndef	__LIBUFS_H__
#define	__LIBUFS_H__

/*
 * libufs structures.
 */

/*
 * userland ufs disk.
 */
struct uufsd {
	const char *d_name;	/* disk name */
	int d_ufs;		/* decimal UFS version */
	int d_fd;		/* raw device file descriptor */
	long d_bsize;		/* device bsize */
	ufs2_daddr_t d_sblock;	/* superblock location */
	struct csum *d_sbcsum;	/* Superblock summary info */
	caddr_t d_inoblock;	/* inode block */
	ino_t d_inomin;		/* low inode */
	ino_t d_inomax;		/* high inode */
	union {
		struct fs d_fs;	/* filesystem information */
		char d_sb[MAXBSIZE];
				/* superblock as buffer */
	} d_sbunion;
	union {
		struct cg d_cg;	/* cylinder group */
		char d_buf[MAXBSIZE];
				/* cylinder group storage */
	} d_cgunion;
	int d_ccg;		/* current cylinder group */
	int d_lcg;		/* last cylinder group (in d_cg) */
	const char *d_error;	/* human readable disk error */
	int d_mine;		/* internal flags */
#define	d_fs	d_sbunion.d_fs
#define	d_sb	d_sbunion.d_sb
#define	d_cg	d_cgunion.d_cg
};

/*
 * libufs macros (internal, non-exported).
 */
#ifdef	_LIBUFS
/*
 * Trace steps through libufs, to be used at entry and erroneous return.
 */
static inline void
ERROR(struct uufsd *u, const char *str)
{

#ifdef	_LIBUFS_DEBUGGING
	if (str != NULL) {
		fprintf(stderr, "libufs: %s", str);
		if (errno != 0)
			fprintf(stderr, ": %s", strerror(errno));
		fprintf(stderr, "\n");
	}
#endif
	if (u != NULL)
		u->d_error = str;
}
#endif	/* _LIBUFS */

__BEGIN_DECLS

/*
 * libufs prototypes.
 */

/*
 * block.c
 */
ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);
int berase(struct uufsd *, ufs2_daddr_t, ufs2_daddr_t);

/*
 * cgroup.c
 */
ufs2_daddr_t cgballoc(struct uufsd *);
int cgbfree(struct uufsd *, ufs2_daddr_t, long);
ino_t cgialloc(struct uufsd *);
int cgread(struct uufsd *);
int cgread1(struct uufsd *, int);
int cgwrite(struct uufsd *);
int cgwrite1(struct uufsd *, int);

/*
 * inode.c
 */
int getino(struct uufsd *, void **, ino_t, int *);
int putino(struct uufsd *);

/*
 * sblock.c
 */
int sbread(struct uufsd *);
int sbwrite(struct uufsd *, int);

/*
 * type.c
 */
int ufs_disk_close(struct uufsd *);
int ufs_disk_fillout(struct uufsd *, const char *);
int ufs_disk_fillout_blank(struct uufsd *, const char *);
int ufs_disk_write(struct uufsd *);

/*
 * ffs_subr.c
 */
void	ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t);
void	ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int);
void	ffs_fragacct(struct fs *, int, int32_t [], int);
int	ffs_isblock(struct fs *, u_char *, ufs1_daddr_t);
int	ffs_isfreeblock(struct fs *, u_char *, ufs1_daddr_t);
void	ffs_setblock(struct fs *, u_char *, ufs1_daddr_t);

__END_DECLS

#endif	/* __LIBUFS_H__ */


code:
/* $FreeBSD: release/9.0.0/lib/libusb/libusb.h 225659 2011-09-19 08:52:06Z hselasky $ */
/*-
 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef __LIBUSB_H__
#define	__LIBUSB_H__

#include <sys/time.h>
#include <sys/types.h>

#ifdef __cplusplus
extern	"C" {
#endif
#if 0
}					/* indent fix */

#endif

/* libusb enums */

enum libusb_class_code {
	LIBUSB_CLASS_PER_INTERFACE = 0,
	LIBUSB_CLASS_AUDIO = 1,
	LIBUSB_CLASS_COMM = 2,
	LIBUSB_CLASS_HID = 3,
	LIBUSB_CLASS_PTP = 6,
	LIBUSB_CLASS_PRINTER = 7,
	LIBUSB_CLASS_MASS_STORAGE = 8,
	LIBUSB_CLASS_HUB = 9,
	LIBUSB_CLASS_DATA = 10,
	LIBUSB_CLASS_VENDOR_SPEC = 0xff,
};

enum libusb_descriptor_type {
	LIBUSB_DT_DEVICE = 0x01,
	LIBUSB_DT_CONFIG = 0x02,
	LIBUSB_DT_STRING = 0x03,
	LIBUSB_DT_INTERFACE = 0x04,
	LIBUSB_DT_ENDPOINT = 0x05,
	LIBUSB_DT_HID = 0x21,
	LIBUSB_DT_REPORT = 0x22,
	LIBUSB_DT_PHYSICAL = 0x23,
	LIBUSB_DT_HUB = 0x29,
};

#define	LIBUSB_DT_DEVICE_SIZE		18
#define	LIBUSB_DT_CONFIG_SIZE		9
#define	LIBUSB_DT_INTERFACE_SIZE	9
#define	LIBUSB_DT_ENDPOINT_SIZE		7
#define	LIBUSB_DT_ENDPOINT_AUDIO_SIZE	9
#define	LIBUSB_DT_HUB_NONVAR_SIZE	7

#define	LIBUSB_ENDPOINT_ADDRESS_MASK	0x0f
#define	LIBUSB_ENDPOINT_DIR_MASK	0x80

enum libusb_endpoint_direction {
	LIBUSB_ENDPOINT_IN = 0x80,
	LIBUSB_ENDPOINT_OUT = 0x00,
};

#define	LIBUSB_TRANSFER_TYPE_MASK	0x03

enum libusb_transfer_type {
	LIBUSB_TRANSFER_TYPE_CONTROL = 0,
	LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
	LIBUSB_TRANSFER_TYPE_BULK = 2,
	LIBUSB_TRANSFER_TYPE_INTERRUPT = 3,
};

enum libusb_standard_request {
	LIBUSB_REQUEST_GET_STATUS = 0x00,
	LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
	LIBUSB_REQUEST_SET_FEATURE = 0x03,
	LIBUSB_REQUEST_SET_ADDRESS = 0x05,
	LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
	LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
	LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
	LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
	LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
	LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
	LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
};

enum libusb_request_type {
	LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
	LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
	LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
	LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5),
};

enum libusb_request_recipient {
	LIBUSB_RECIPIENT_DEVICE = 0x00,
	LIBUSB_RECIPIENT_INTERFACE = 0x01,
	LIBUSB_RECIPIENT_ENDPOINT = 0x02,
	LIBUSB_RECIPIENT_OTHER = 0x03,
};

#define	LIBUSB_ISO_SYNC_TYPE_MASK	0x0C

enum libusb_iso_sync_type {
	LIBUSB_ISO_SYNC_TYPE_NONE = 0,
	LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
	LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
	LIBUSB_ISO_SYNC_TYPE_SYNC = 3,
};

#define	LIBUSB_ISO_USAGE_TYPE_MASK 0x30

enum libusb_iso_usage_type {
	LIBUSB_ISO_USAGE_TYPE_DATA = 0,
	LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
	LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
};

enum libusb_error {
	LIBUSB_SUCCESS = 0,
	LIBUSB_ERROR_IO = -1,
	LIBUSB_ERROR_INVALID_PARAM = -2,
	LIBUSB_ERROR_ACCESS = -3,
	LIBUSB_ERROR_NO_DEVICE = -4,
	LIBUSB_ERROR_NOT_FOUND = -5,
	LIBUSB_ERROR_BUSY = -6,
	LIBUSB_ERROR_TIMEOUT = -7,
	LIBUSB_ERROR_OVERFLOW = -8,
	LIBUSB_ERROR_PIPE = -9,
	LIBUSB_ERROR_INTERRUPTED = -10,
	LIBUSB_ERROR_NO_MEM = -11,
	LIBUSB_ERROR_NOT_SUPPORTED = -12,
	LIBUSB_ERROR_OTHER = -99,
};

enum libusb_speed {
	LIBUSB_SPEED_UNKNOWN = 0,
	LIBUSB_SPEED_LOW = 1,
	LIBUSB_SPEED_FULL = 2,
	LIBUSB_SPEED_HIGH = 3,
	LIBUSB_SPEED_SUPER = 4,
};

enum libusb_transfer_status {
	LIBUSB_TRANSFER_COMPLETED,
	LIBUSB_TRANSFER_ERROR,
	LIBUSB_TRANSFER_TIMED_OUT,
	LIBUSB_TRANSFER_CANCELLED,
	LIBUSB_TRANSFER_STALL,
	LIBUSB_TRANSFER_NO_DEVICE,
	LIBUSB_TRANSFER_OVERFLOW,
};

enum libusb_transfer_flags {
	LIBUSB_TRANSFER_SHORT_NOT_OK = 1 << 0,
	LIBUSB_TRANSFER_FREE_BUFFER = 1 << 1,
	LIBUSB_TRANSFER_FREE_TRANSFER = 1 << 2,
};

enum libusb_debug_level {
	LIBUSB_DEBUG_NO=0,
	LIBUSB_DEBUG_FUNCTION=1,
	LIBUSB_DEBUG_TRANSFER=2,
};

/* libusb structures */

struct libusb_context;
struct libusb_device;
struct libusb_transfer;
struct libusb_device_handle;

struct libusb_pollfd {
	int	fd;
	short	events;
};

typedef struct libusb_context libusb_context;
typedef struct libusb_device libusb_device;
typedef struct libusb_device_handle libusb_device_handle;
typedef struct libusb_pollfd libusb_pollfd;
typedef void (*libusb_pollfd_added_cb) (int fd, short events, void *user_data);
typedef void (*libusb_pollfd_removed_cb) (int fd, void *user_data);

typedef struct libusb_device_descriptor {
	uint8_t	bLength;
	uint8_t	bDescriptorType;
	uint16_t bcdUSB;
	uint8_t	bDeviceClass;
	uint8_t	bDeviceSubClass;
	uint8_t	bDeviceProtocol;
	uint8_t	bMaxPacketSize0;
	uint16_t idVendor;
	uint16_t idProduct;
	uint16_t bcdDevice;
	uint8_t	iManufacturer;
	uint8_t	iProduct;
	uint8_t	iSerialNumber;
	uint8_t	bNumConfigurations;
}	libusb_device_descriptor;

typedef struct libusb_endpoint_descriptor {
	uint8_t	bLength;
	uint8_t	bDescriptorType;
	uint8_t	bEndpointAddress;
	uint8_t	bmAttributes;
	uint16_t wMaxPacketSize;
	uint8_t	bInterval;
	uint8_t	bRefresh;
	uint8_t	bSynchAddress;
	uint8_t *extra;
	int	extra_length;
}	libusb_endpoint_descriptor __aligned(sizeof(void *));

typedef struct libusb_interface_descriptor {
	uint8_t	bLength;
	uint8_t	bDescriptorType;
	uint8_t	bInterfaceNumber;
	uint8_t	bAlternateSetting;
	uint8_t	bNumEndpoints;
	uint8_t	bInterfaceClass;
	uint8_t	bInterfaceSubClass;
	uint8_t	bInterfaceProtocol;
	uint8_t	iInterface;
	struct libusb_endpoint_descriptor *endpoint;
	uint8_t *extra;
	int	extra_length;
}	libusb_interface_descriptor __aligned(sizeof(void *));

typedef struct libusb_interface {
	struct libusb_interface_descriptor *altsetting;
	int	num_altsetting;
}	libusb_interface __aligned(sizeof(void *));

typedef struct libusb_config_descriptor {
	uint8_t	bLength;
	uint8_t	bDescriptorType;
	uint16_t wTotalLength;
	uint8_t	bNumInterfaces;
	uint8_t	bConfigurationValue;
	uint8_t	iConfiguration;
	uint8_t	bmAttributes;
	uint8_t	MaxPower;
	struct libusb_interface *interface;
	uint8_t *extra;
	int	extra_length;
}	libusb_config_descriptor __aligned(sizeof(void *));

typedef struct libusb_control_setup {
	uint8_t	bmRequestType;
	uint8_t	bRequest;
	uint16_t wValue;
	uint16_t wIndex;
	uint16_t wLength;
}	libusb_control_setup;

#define	LIBUSB_CONTROL_SETUP_SIZE	8	/* bytes */

typedef struct libusb_iso_packet_descriptor {
	uint32_t length;
	uint32_t actual_length;
	enum libusb_transfer_status status;
}	libusb_iso_packet_descriptor __aligned(sizeof(void *));

typedef void (*libusb_transfer_cb_fn) (struct libusb_transfer *transfer);

typedef struct libusb_transfer {
	libusb_device_handle *dev_handle;
	uint8_t	flags;
	uint32_t endpoint;
	uint8_t type;
	uint32_t timeout;
	enum libusb_transfer_status status;
	int	length;
	int	actual_length;
	libusb_transfer_cb_fn callback;
	void   *user_data;
	uint8_t *buffer;
	void *os_priv;
	int	num_iso_packets;
	struct libusb_iso_packet_descriptor iso_packet_desc[0];
}	libusb_transfer __aligned(sizeof(void *));

/* Library initialisation */

void	libusb_set_debug(libusb_context * ctx, int level);
const char *libusb_strerror(int code);
const char *libusb_error_name(int code);
int	libusb_init(libusb_context ** context);
void	libusb_exit(struct libusb_context *ctx);

/* Device handling and enumeration */

ssize_t libusb_get_device_list(libusb_context * ctx, libusb_device *** list);
void	libusb_free_device_list(libusb_device ** list, int unref_devices);
uint8_t	libusb_get_bus_number(libusb_device * dev);
uint8_t	libusb_get_device_address(libusb_device * dev);
enum libusb_speed libusb_get_device_speed(libusb_device * dev);
int	libusb_clear_halt(libusb_device_handle *devh, uint8_t endpoint);
int	libusb_get_max_packet_size(libusb_device * dev, uint8_t endpoint);
libusb_device *libusb_ref_device(libusb_device * dev);
void	libusb_unref_device(libusb_device * dev);
int	libusb_open(libusb_device * dev, libusb_device_handle ** devh);
libusb_device_handle *libusb_open_device_with_vid_pid(libusb_context * ctx, uint16_t vendor_id, uint16_t product_id);
void	libusb_close(libusb_device_handle * devh);
libusb_device *libusb_get_device(libusb_device_handle * devh);
int	libusb_get_configuration(libusb_device_handle * devh, int *config);
int	libusb_set_configuration(libusb_device_handle * devh, int configuration);
int	libusb_claim_interface(libusb_device_handle * devh, int interface_number);
int	libusb_release_interface(libusb_device_handle * devh, int interface_number);
int	libusb_reset_device(libusb_device_handle * devh);
int	libusb_check_connected(libusb_device_handle * devh);
int 	libusb_kernel_driver_active(libusb_device_handle * devh, int interface);
int	libusb_get_driver_np(libusb_device_handle * devh, int interface, char *name, int namelen);
int	libusb_get_driver(libusb_device_handle * devh, int interface, char *name, int namelen);
int 	libusb_detach_kernel_driver_np(libusb_device_handle * devh, int interface);
int 	libusb_detach_kernel_driver(libusb_device_handle * devh, int interface);
int 	libusb_attach_kernel_driver(libusb_device_handle * devh, int interface);
int	libusb_set_interface_alt_setting(libusb_device_handle * devh, int interface_number, int alternate_setting);

/* USB Descriptors */

int	libusb_get_device_descriptor(libusb_device * dev, struct libusb_device_descriptor *desc);
int	libusb_get_active_config_descriptor(libusb_device * dev, struct libusb_config_descriptor **config);
int	libusb_get_config_descriptor(libusb_device * dev, uint8_t config_index, struct libusb_config_descriptor **config);
int	libusb_get_config_descriptor_by_value(libusb_device * dev, uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
void	libusb_free_config_descriptor(struct libusb_config_descriptor *config);
int	libusb_get_string_descriptor_ascii(libusb_device_handle * devh, uint8_t desc_index, uint8_t *data, int length);
int	libusb_get_descriptor(libusb_device_handle * devh, uint8_t desc_type, uint8_t desc_index, uint8_t *data, int length);

/* Asynchronous device I/O */

struct libusb_transfer *libusb_alloc_transfer(int iso_packets);
void	libusb_free_transfer(struct libusb_transfer *transfer);
int	libusb_submit_transfer(struct libusb_transfer *transfer);
int	libusb_cancel_transfer(struct libusb_transfer *transfer);
uint8_t *libusb_get_iso_packet_buffer(struct libusb_transfer *transfer, uint32_t index);
uint8_t *libusb_get_iso_packet_buffer_simple(struct libusb_transfer *transfer, uint32_t index);
void	libusb_set_iso_packet_lengths(struct libusb_transfer *transfer, uint32_t length);
uint8_t *libusb_control_transfer_get_data(struct libusb_transfer *transfer);
struct libusb_control_setup *libusb_control_transfer_get_setup(struct libusb_transfer *transfer);
void	libusb_fill_control_setup(uint8_t *buf, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength);
void	libusb_fill_control_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t *buf, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout);
void	libusb_fill_bulk_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf, int length, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout);
void	libusb_fill_interrupt_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf, int length, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout);
void	libusb_fill_iso_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf, int length, int npacket, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout);

/* Polling and timing */

int	libusb_try_lock_events(libusb_context * ctx);
void	libusb_lock_events(libusb_context * ctx);
void	libusb_unlock_events(libusb_context * ctx);
int	libusb_event_handling_ok(libusb_context * ctx);
int	libusb_event_handler_active(libusb_context * ctx);
void	libusb_lock_event_waiters(libusb_context * ctx);
void	libusb_unlock_event_waiters(libusb_context * ctx);
int	libusb_wait_for_event(libusb_context * ctx, struct timeval *tv);
int	libusb_handle_events_timeout(libusb_context * ctx, struct timeval *tv);
int	libusb_handle_events(libusb_context * ctx);
int	libusb_handle_events_locked(libusb_context * ctx, struct timeval *tv);
int	libusb_get_next_timeout(libusb_context * ctx, struct timeval *tv);
void	libusb_set_pollfd_notifiers(libusb_context * ctx, libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, void *user_data);
struct libusb_pollfd **libusb_get_pollfds(libusb_context * ctx);

/* Synchronous device I/O */

int	libusb_control_transfer(libusb_device_handle * devh, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t *data, uint16_t wLength, uint32_t timeout);
int	libusb_bulk_transfer(libusb_device_handle * devh, uint8_t endpoint, uint8_t *data, int length, int *transferred, uint32_t timeout);
int	libusb_interrupt_transfer(libusb_device_handle * devh, uint8_t endpoint, uint8_t *data, int length, int *transferred, uint32_t timeout);

/* Byte-order */

uint16_t libusb_cpu_to_le16(uint16_t x);
uint16_t libusb_le16_to_cpu(uint16_t x);

#if 0
{					/* indent fix */
#endif
#ifdef __cplusplus
}

#endif

#endif					/* __LIBUSB_H__ */