code:
/*-
 * Copyright (c) 1992, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software developed by the Computer Systems
 * Engineering group at Lawrence Berkeley Laboratory under DARPA
 * contract BG 91-66 and contributed to Berkeley.
 *
 * 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.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * 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.
 *
 *	@(#)fbio.h	8.2 (Berkeley) 10/30/93
 *
 * $FreeBSD: release/9.0.0/sys/sys/fbio.h 204265 2010-02-23 21:51:14Z jkim $
 */

#ifndef _SYS_FBIO_H_
#define _SYS_FBIO_H_

#ifndef _KERNEL
#include <sys/types.h>
#endif
#include <sys/ioccom.h>

/*
 * Frame buffer ioctls (from Sprite, trimmed to essentials for X11).
 */

/*
 * Frame buffer type codes.
 */
#define	FBTYPE_SUN1BW		0	/* multibus mono */
#define	FBTYPE_SUN1COLOR	1	/* multibus color */
#define	FBTYPE_SUN2BW		2	/* memory mono */
#define	FBTYPE_SUN2COLOR	3	/* color w/rasterop chips */
#define	FBTYPE_SUN2GP		4	/* GP1/GP2 */
#define	FBTYPE_SUN5COLOR	5	/* RoadRunner accelerator */
#define	FBTYPE_SUN3COLOR	6	/* memory color */
#define	FBTYPE_MEMCOLOR		7	/* memory 24-bit */
#define	FBTYPE_SUN4COLOR	8	/* memory color w/overlay */

#define	FBTYPE_NOTSUN1		9	/* reserved for customer */
#define	FBTYPE_NOTSUN2		10	/* reserved for customer */
#define	FBTYPE_PCIMISC		11	/* (generic) PCI misc. disp. */

#define	FBTYPE_SUNFAST_COLOR	12	/* accelerated 8bit */
#define	FBTYPE_SUNROP_COLOR	13	/* MEMCOLOR with rop h/w */
#define	FBTYPE_SUNFB_VIDEO	14	/* Simple video mixing */
#define	FBTYPE_RESERVED5	15	/* reserved, do not use */
#define	FBTYPE_RESERVED4	16	/* reserved, do not use */
#define	FBTYPE_SUNGP3		17
#define	FBTYPE_SUNGT		18
#define	FBTYPE_SUNLEO		19	/* zx Leo */

#define	FBTYPE_MDA		20
#define	FBTYPE_HERCULES		21
#define	FBTYPE_CGA		22
#define	FBTYPE_EGA		23
#define	FBTYPE_VGA		24
#define	FBTYPE_PC98		25
#define	FBTYPE_TGA		26
#define	FBTYPE_TGA2		27

#define	FBTYPE_MDICOLOR		28	/* cg14 */
#define	FBTYPE_TCXCOLOR		29	/* SUNW,tcx */
#define	FBTYPE_CREATOR		30

#define	FBTYPE_LASTPLUSONE	31	/* max number of fbs (change as add) */

/*
 * Frame buffer descriptor as returned by FBIOGTYPE.
 */
struct fbtype {
	int	fb_type;	/* as defined above */
	int	fb_height;	/* in pixels */
	int	fb_width;	/* in pixels */
	int	fb_depth;	/* bits per pixel */
	int	fb_cmsize;	/* size of color map (entries) */
	int	fb_size;	/* total size in bytes */
};
#define	FBIOGTYPE	_IOR('F', 0, struct fbtype)

#ifdef notdef
/*
 * General purpose structure for passing info in and out of frame buffers
 * (used for gp1) -- unsupported.
 */
struct fbinfo {
	int	fb_physaddr;	/* physical frame buffer address */
	int	fb_hwwidth;	/* fb board width */
	int	fb_hwheight;	/* fb board height */
	int	fb_addrdelta;	/* phys addr diff between boards */
	u_char	*fb_ropaddr;	/* fb virtual addr */
	int	fb_unit;	/* minor devnum of fb */
};
#define	FBIOGINFO	_IOR('F', 2, struct fbinfo)
#endif

/*
 * Color map I/O.
 */
struct fbcmap {
	int	index;		/* first element (0 origin) */
	int	count;		/* number of elements */
	u_char	*red;		/* red color map elements */
	u_char	*green;		/* green color map elements */
	u_char	*blue;		/* blue color map elements */
};
#define	FBIOPUTCMAP	_IOW('F', 3, struct fbcmap)
#define	FBIOGETCMAP	_IOW('F', 4, struct fbcmap)

/*
 * Set/get attributes.
 */
#define	FB_ATTR_NDEVSPECIFIC	8	/* no. of device specific values */
#define	FB_ATTR_NEMUTYPES	4	/* no. of emulation types */

struct fbsattr {
	int	flags;			/* flags; see below */
	int	emu_type;		/* emulation type (-1 if unused) */
	int	dev_specific[FB_ATTR_NDEVSPECIFIC];	/* catchall */
};
#define	FB_ATTR_AUTOINIT	1	/* emulation auto init flag */
#define	FB_ATTR_DEVSPECIFIC	2	/* dev. specific stuff valid flag */

struct fbgattr {
	int	real_type;		/* real device type */
	int	owner;			/* PID of owner, 0 if myself */
	struct	fbtype fbtype;		/* fbtype info for real device */
	struct	fbsattr sattr;		/* see above */
	int	emu_types[FB_ATTR_NEMUTYPES];	/* possible emulations */
						/* (-1 if unused) */
};
#define	FBIOSATTR	_IOW('F', 5, struct fbsattr)
#define	FBIOGATTR	_IOR('F', 6, struct fbgattr)

/*
 * Video control.
 */
#define	FBVIDEO_OFF		0
#define	FBVIDEO_ON		1

#define	FBIOSVIDEO	_IOW('F', 7, int)
#define	FBIOGVIDEO	_IOR('F', 8, int)

/* vertical retrace */
#define	FBIOVERTICAL	_IO('F', 9)

/*
 * Hardware cursor control (for, e.g., CG6).  A rather complex and icky
 * interface that smells like VMS, but there it is....
 */
struct fbcurpos {
	short	x;
	short	y;
};

struct fbcursor {
	short	set;		/* flags; see below */
	short	enable;		/* nonzero => cursor on, 0 => cursor off */
	struct	fbcurpos pos;	/* position on display */
	struct	fbcurpos hot;	/* hot-spot within cursor */
	struct	fbcmap cmap;	/* cursor color map */
	struct	fbcurpos size;	/* number of valid bits in image & mask */
	caddr_t	image;		/* cursor image bits */
	caddr_t	mask;		/* cursor mask bits */
};
#define	FB_CUR_SETCUR	0x01	/* set on/off (i.e., obey fbcursor.enable) */
#define	FB_CUR_SETPOS	0x02	/* set position */
#define	FB_CUR_SETHOT	0x04	/* set hot-spot */
#define	FB_CUR_SETCMAP	0x08	/* set cursor color map */
#define	FB_CUR_SETSHAPE	0x10	/* set size & bits */
#define	FB_CUR_SETALL	(FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT | \
			 FB_CUR_SETCMAP | FB_CUR_SETSHAPE)

/* controls for cursor attributes & shape (including position) */
#define	FBIOSCURSOR	_IOW('F', 24, struct fbcursor)
#define	FBIOGCURSOR	_IOWR('F', 25, struct fbcursor)

/* controls for cursor position only */
#define	FBIOSCURPOS	_IOW('F', 26, struct fbcurpos)
#define	FBIOGCURPOS	_IOW('F', 27, struct fbcurpos)

/* get maximum cursor size */
#define	FBIOGCURMAX	_IOR('F', 28, struct fbcurpos)

/*
 * Video board information
 */
struct brd_info {
	u_short		accessible_width; /* accessible bytes in scanline */
	u_short		accessible_height; /* number of accessible scanlines */
	u_short		line_bytes;	/* number of bytes/scanline */
	u_short		hdb_capable;	/* can this thing hardware db? */
	u_short		vmsize;		/* video memory size */
	u_char		boardrev;	/* board revision # */
	u_char		pad0;
	u_long		pad1;
};
#define	FBIOGXINFO	_IOR('F', 39, struct brd_info)

/*
 * Monitor information
 */
struct mon_info {
	u_long		mon_type;	/* bit array */
#define MON_TYPE_STEREO		0x8	/* stereo display */
#define MON_TYPE_0_OFFSET	0x4	/* black level 0 ire instead of 7.5 */
#define MON_TYPE_OVERSCAN	0x2	/* overscan */
#define MON_TYPE_GRAY		0x1	/* greyscale monitor */
	u_long		pixfreq;	/* pixel frequency in Hz */
	u_long		hfreq;		/* horizontal freq in Hz */
	u_long		vfreq;		/* vertical freq in Hz */
	u_long		vsync;		/* vertical sync in scanlines */
	u_long		hsync;		/* horizontal sync in pixels */
	/* these are in pixel units */
	u_short		hfporch;	/* horizontal front porch */
	u_short		hbporch;	/* horizontal back porch */
	u_short		vfporch;	/* vertical front porch */
	u_short		vbporch;	/* vertical back porch */
};
#define	FBIOMONINFO	_IOR('F', 40, struct mon_info)

/*
 * Color map I/O.
 */
struct fbcmap_i {
	unsigned int	flags;
#define	FB_CMAP_BLOCK	(1 << 0)	/* wait for vertical refresh */
#define	FB_CMAP_KERNEL	(1 << 1)	/* called within kernel */
	int		id;		/* color map id */
	int		index;		/* first element (0 origin) */
	int		count;		/* number of elements */
	u_char		*red;		/* red color map elements */
	u_char		*green;		/* green color map elements */
	u_char		*blue;		/* blue color map elements */
};
#define	FBIOPUTCMAPI	_IOW('F', 41, struct fbcmap_i)
#define	FBIOGETCMAPI	_IOW('F', 42, struct fbcmap_i)

/* The new style frame buffer ioctls. */

/* video mode information block */
struct video_info {
    int			vi_mode;	/* mode number, see below */
    int			vi_flags;
#define V_INFO_COLOR	(1 << 0)
#define V_INFO_GRAPHICS	(1 << 1)
#define V_INFO_LINEAR	(1 << 2)
#define V_INFO_VESA	(1 << 3)
#define	V_INFO_NONVGA	(1 << 4)
    int			vi_width;
    int			vi_height;
    int			vi_cwidth;
    int			vi_cheight;
    int			vi_depth;
    int			vi_planes;
    vm_offset_t		vi_window;	/* physical address */
    size_t		vi_window_size;
    size_t		vi_window_gran;
    vm_offset_t		vi_buffer;	/* physical address */
    size_t		vi_buffer_size;
    int			vi_mem_model;
#define V_INFO_MM_OTHER  (-1)
#define V_INFO_MM_TEXT	 0
#define V_INFO_MM_PLANAR 1
#define V_INFO_MM_PACKED 2
#define V_INFO_MM_DIRECT 3
#define V_INFO_MM_CGA	 100
#define V_INFO_MM_HGC	 101
#define V_INFO_MM_VGAX	 102
    /* for MM_PACKED and MM_DIRECT only */
    int			vi_pixel_size;	/* in bytes */
    /* for MM_DIRECT only */
    int			vi_pixel_fields[4];	/* RGB and reserved fields */
    int			vi_pixel_fsizes[4];
    /* reserved */
    u_char		vi_reserved[64];
    vm_offset_t		vi_registers;	/* physical address */
    vm_offset_t		vi_registers_size;
};
typedef struct video_info video_info_t;

/* adapter infromation block */
struct video_adapter {
    int			va_index;
    int			va_type;
#define KD_OTHER	0		/* unknown */
#define KD_MONO		1		/* monochrome adapter */
#define KD_HERCULES	2		/* hercules adapter */
#define KD_CGA		3		/* color graphics adapter */
#define KD_EGA		4		/* enhanced graphics adapter */
#define KD_VGA		5		/* video graphics adapter */
#define KD_PC98		6		/* PC-98 display */
#define KD_TGA		7		/* TGA */
#define KD_TGA2		8		/* TGA2 */
    char		*va_name;
    int			va_unit;
    int			va_minor;
    int			va_flags;
#define V_ADP_COLOR	(1 << 0)
#define V_ADP_MODECHANGE (1 << 1)
#define V_ADP_STATESAVE	(1 << 2)
#define V_ADP_STATELOAD	(1 << 3)
#define V_ADP_FONT	(1 << 4)
#define V_ADP_PALETTE	(1 << 5)
#define V_ADP_BORDER	(1 << 6)
#define V_ADP_VESA	(1 << 7)
#define V_ADP_BOOTDISPLAY (1 << 8)
#define V_ADP_PROBED	(1 << 16)
#define V_ADP_INITIALIZED (1 << 17)
#define V_ADP_REGISTERED (1 << 18)
#define V_ADP_ATTACHED	(1 << 19)
#define	V_ADP_DAC8	(1 << 20)
    vm_offset_t		va_io_base;
    int			va_io_size;
    vm_offset_t		va_crtc_addr;
    vm_offset_t		va_mem_base;
    int			va_mem_size;
    vm_offset_t		va_window;	/* virtual address */
    size_t		va_window_size;
    size_t		va_window_gran;
    u_int		va_window_orig;
    vm_offset_t		va_buffer;	/* virtual address */
    size_t		va_buffer_size;
    int			va_initial_mode;
    int			va_initial_bios_mode;
    int			va_mode;
    struct video_info	va_info;
    int			va_line_width;
    struct {
	int		x;
	int		y;
    } 			va_disp_start;
    void		*va_token;
    int			va_model;
    int			va_little_bitian;
    int			va_little_endian;
    int			va_buffer_alias;
    vm_offset_t		va_registers;	/* virtual address */
    vm_offset_t		va_registers_size;
};
typedef struct video_adapter video_adapter_t;

struct video_adapter_info {
    int			va_index;
    int			va_type;
    char		va_name[16];
    int			va_unit;
    int			va_flags;
    vm_offset_t		va_io_base;
    int			va_io_size;
    vm_offset_t		va_crtc_addr;
    vm_offset_t		va_mem_base;
    int			va_mem_size;
    vm_offset_t		va_window;	/* virtual address */
    size_t		va_window_size;
    size_t		va_window_gran;
    vm_offset_t		va_unused0;
    size_t		va_buffer_size;
    int			va_initial_mode;
    int			va_initial_bios_mode;
    int			va_mode;
    int			va_line_width;
    struct {
	int		x;
	int		y;
    } 			va_disp_start;
    u_int		va_window_orig;
    /* reserved */
    u_char		va_reserved[64];
};
typedef struct video_adapter_info video_adapter_info_t;

/* some useful video adapter index */
#define V_ADP_PRIMARY	0
#define V_ADP_SECONDARY	1

/* video mode numbers */

#define M_B40x25	0	/* black & white 40 columns */
#define M_C40x25	1	/* color 40 columns */
#define M_B80x25	2	/* black & white 80 columns */
#define M_C80x25	3	/* color 80 columns */
#define M_BG320		4	/* black & white graphics 320x200 */
#define M_CG320		5	/* color graphics 320x200 */
#define M_BG640		6	/* black & white graphics 640x200 hi-res */
#define M_EGAMONO80x25  7       /* ega-mono 80x25 */
#define M_CG320_D	13	/* ega mode D */
#define M_CG640_E	14	/* ega mode E */
#define M_EGAMONOAPA	15	/* ega mode F */
#define M_CG640x350	16	/* ega mode 10 */
#define M_ENHMONOAPA2	17	/* ega mode F with extended memory */
#define M_ENH_CG640	18	/* ega mode 10* */
#define M_ENH_B40x25    19      /* ega enhanced black & white 40 columns */
#define M_ENH_C40x25    20      /* ega enhanced color 40 columns */
#define M_ENH_B80x25    21      /* ega enhanced black & white 80 columns */
#define M_ENH_C80x25    22      /* ega enhanced color 80 columns */
#define M_VGA_C40x25	23	/* vga 8x16 font on color */
#define M_VGA_C80x25	24	/* vga 8x16 font on color */
#define M_VGA_M80x25	25	/* vga 8x16 font on mono */

#define M_VGA11		26	/* vga 640x480 2 colors */
#define M_BG640x480	26
#define M_VGA12		27	/* vga 640x480 16 colors */
#define M_CG640x480	27
#define M_VGA13		28	/* vga 320x200 256 colors */
#define M_VGA_CG320	28

#define M_VGA_C80x50	30	/* vga 8x8 font on color */
#define M_VGA_M80x50	31	/* vga 8x8 font on color */
#define M_VGA_C80x30	32	/* vga 8x16 font on color */
#define M_VGA_M80x30	33	/* vga 8x16 font on color */
#define M_VGA_C80x60	34	/* vga 8x8 font on color */
#define M_VGA_M80x60	35	/* vga 8x8 font on color */
#define M_VGA_CG640	36	/* vga 640x400 256 color */
#define M_VGA_MODEX	37	/* vga 320x240 256 color */

#define M_VGA_C90x25	40	/* vga 8x16 font on color */
#define M_VGA_M90x25	41	/* vga 8x16 font on mono */
#define M_VGA_C90x30	42	/* vga 8x16 font on color */
#define M_VGA_M90x30	43	/* vga 8x16 font on mono */
#define M_VGA_C90x43	44	/* vga 8x8 font on color */
#define M_VGA_M90x43	45	/* vga 8x8 font on mono */
#define M_VGA_C90x50	46	/* vga 8x8 font on color */
#define M_VGA_M90x50	47	/* vga 8x8 font on mono */
#define M_VGA_C90x60	48	/* vga 8x8 font on color */
#define M_VGA_M90x60	49	/* vga 8x8 font on mono */

#define M_ENH_B80x43	0x70	/* ega black & white 80x43 */
#define M_ENH_C80x43	0x71	/* ega color 80x43 */

#define M_PC98_80x25		98	/* PC98 text 80x25 */
#define M_PC98_80x30		99	/* PC98 text 80x30 */
#define M_PC98_EGC640x400	100	/* PC98 graphic 640x400 16 colors */
#define M_PC98_PEGC640x400	101	/* PC98 graphic 640x400 256 colors */
#define M_PC98_PEGC640x480	102	/* PC98 graphic 640x480 256 colors */

#define M_HGC_P0	0xe0	/* hercules graphics - page 0 @ B0000 */
#define M_HGC_P1	0xe1	/* hercules graphics - page 1 @ B8000 */
#define M_MCA_MODE	0xff	/* monochrome adapter mode */

#define M_TEXT_80x25	200	/* generic text modes */
#define M_TEXT_80x30	201
#define M_TEXT_80x43	202
#define M_TEXT_80x50	203
#define M_TEXT_80x60	204
#define M_TEXT_132x25	205
#define M_TEXT_132x30	206
#define M_TEXT_132x43	207
#define M_TEXT_132x50	208
#define M_TEXT_132x60	209

#define M_VESA_BASE		0x100	/* VESA mode number base */
#define M_VESA_CG640x400	0x100	/* 640x400, 256 color */
#define M_VESA_CG640x480	0x101	/* 640x480, 256 color */
#define M_VESA_800x600		0x102	/* 800x600, 16 color */
#define M_VESA_CG800x600	0x103	/* 800x600, 256 color */
#define M_VESA_1024x768		0x104	/* 1024x768, 16 color */
#define M_VESA_CG1024x768	0x105	/* 1024x768, 256 color */
#define M_VESA_1280x1024	0x106	/* 1280x1024, 16 color */
#define M_VESA_CG1280x1024	0x107	/* 1280x1024, 256 color */
#define M_VESA_C80x60		0x108	/* 8x8 font */
#define M_VESA_C132x25		0x109	/* 8x16 font */
#define M_VESA_C132x43		0x10a	/* 8x14 font */
#define M_VESA_C132x50		0x10b	/* 8x8 font */
#define M_VESA_C132x60		0x10c	/* 8x8 font */
#define M_VESA_32K_320		0x10d	/* 320x200, 5:5:5 */
#define M_VESA_64K_320		0x10e	/* 320x200, 5:6:5 */
#define M_VESA_FULL_320		0x10f	/* 320x200, 8:8:8 */
#define M_VESA_32K_640		0x110	/* 640x480, 5:5:5 */
#define M_VESA_64K_640		0x111	/* 640x480, 5:6:5 */
#define M_VESA_FULL_640		0x112	/* 640x480, 8:8:8 */
#define M_VESA_32K_800		0x113	/* 800x600, 5:5:5 */
#define M_VESA_64K_800		0x114	/* 800x600, 5:6:5 */
#define M_VESA_FULL_800		0x115	/* 800x600, 8:8:8 */
#define M_VESA_32K_1024		0x116	/* 1024x768, 5:5:5 */
#define M_VESA_64K_1024		0x117	/* 1024x768, 5:6:5 */
#define M_VESA_FULL_1024	0x118	/* 1024x768, 8:8:8 */
#define M_VESA_32K_1280		0x119	/* 1280x1024, 5:5:5 */
#define M_VESA_64K_1280		0x11a	/* 1280x1024, 5:6:5 */
#define M_VESA_FULL_1280	0x11b	/* 1280x1024, 8:8:8 */
#define M_VESA_MODE_MAX		0x1ff

struct video_display_start {
	int		x;
	int		y;
};
typedef struct video_display_start video_display_start_t;

struct video_color_palette {
	int		index;		/* first element (zero-based) */
	int		count;		/* number of elements */
	u_char		*red;		/* red */
	u_char		*green;		/* green */
	u_char		*blue;		/* blue */
	u_char		*transparent;	/* may be NULL */
};
typedef struct video_color_palette video_color_palette_t;

/* adapter info. */
#define FBIO_ADAPTER	_IOR('F', 100, int)
#define FBIO_ADPTYPE	_IOR('F', 101, int)
#define FBIO_ADPINFO	_IOR('F', 102, struct video_adapter_info)

/* video mode control */
#define FBIO_MODEINFO	_IOWR('F', 103, struct video_info)
#define FBIO_FINDMODE	_IOWR('F', 104, struct video_info)
#define FBIO_GETMODE	_IOR('F', 105, int)
#define FBIO_SETMODE	_IOW('F', 106, int)

/* get/set frame buffer window origin */
#define FBIO_GETWINORG	_IOR('F', 107, u_int)
#define FBIO_SETWINORG	_IOW('F', 108, u_int)

/* get/set display start address */
#define FBIO_GETDISPSTART	_IOR('F', 109, video_display_start_t)
#define FBIO_SETDISPSTART	_IOW('F', 110, video_display_start_t)

/* get/set scan line width */
#define FBIO_GETLINEWIDTH	_IOR('F', 111, u_int)
#define FBIO_SETLINEWIDTH	_IOW('F', 112, u_int)

/* color palette control */
#define FBIO_GETPALETTE	_IOW('F', 113, video_color_palette_t)
#define FBIO_SETPALETTE	_IOW('F', 114, video_color_palette_t)

/* blank display */
#define V_DISPLAY_ON		0
#define V_DISPLAY_BLANK		1
#define V_DISPLAY_STAND_BY	2
#define V_DISPLAY_SUSPEND	3

#define FBIO_BLANK	_IOW('F', 115, int)

#endif /* !_SYS_FBIO_H_ */


code:
/*-
 * Copyright (c) 1983, 1990, 1993
 *	The Regents of the University of California.  All rights reserved.
 * (c) UNIX System Laboratories, Inc.
 * All or some portions of this file are derived from material licensed
 * to the University of California by American Telephone and Telegraph
 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
 * the permission of UNIX System Laboratories, Inc.
 *
 * 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.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * 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.
 *
 *	@(#)fcntl.h	8.3 (Berkeley) 1/21/94
 * $FreeBSD: release/9.0.0/sys/sys/fcntl.h 220791 2011-04-18 16:32:22Z mdf $
 */

#ifndef _SYS_FCNTL_H_
#define	_SYS_FCNTL_H_

/*
 * This file includes the definitions for open and fcntl
 * described by POSIX for <fcntl.h>; it also includes
 * related kernel definitions.
 */

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

#ifndef _MODE_T_DECLARED
typedef	__mode_t	mode_t;
#define	_MODE_T_DECLARED
#endif

#ifndef _OFF_T_DECLARED
typedef	__off_t		off_t;
#define	_OFF_T_DECLARED
#endif

#ifndef _PID_T_DECLARED
typedef	__pid_t		pid_t;
#define	_PID_T_DECLARED
#endif

/*
 * File status flags: these are used by open(2), fcntl(2).
 * They are also used (indirectly) in the kernel file structure f_flags,
 * which is a superset of the open/fcntl flags.  Open flags and f_flags
 * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
 * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
 */
/* open-only flags */
#define	O_RDONLY	0x0000		/* open for reading only */
#define	O_WRONLY	0x0001		/* open for writing only */
#define	O_RDWR		0x0002		/* open for reading and writing */
#define	O_ACCMODE	0x0003		/* mask for above modes */

/*
 * Kernel encoding of open mode; separate read and write bits that are
 * independently testable: 1 greater than the above.
 *
 * XXX
 * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
 * which was documented to use FREAD/FWRITE, continues to work.
 */
#if __BSD_VISIBLE
#define	FREAD		0x0001
#define	FWRITE		0x0002
#endif
#define	O_NONBLOCK	0x0004		/* no delay */
#define	O_APPEND	0x0008		/* set append mode */
#if __BSD_VISIBLE
#define	O_SHLOCK	0x0010		/* open with shared file lock */
#define	O_EXLOCK	0x0020		/* open with exclusive file lock */
#define	O_ASYNC		0x0040		/* signal pgrp when data ready */
#define	O_FSYNC		0x0080		/* synchronous writes */
#endif
#define	O_SYNC		0x0080		/* POSIX synonym for O_FSYNC */
#if __BSD_VISIBLE
#define	O_NOFOLLOW	0x0100		/* don't follow symlinks */
#endif
#define	O_CREAT		0x0200		/* create if nonexistent */
#define	O_TRUNC		0x0400		/* truncate to zero length */
#define	O_EXCL		0x0800		/* error if already exists */
#ifdef _KERNEL
#define	FHASLOCK	0x4000		/* descriptor holds advisory lock */
#endif

/* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */
#define	O_NOCTTY	0x8000		/* don't assign controlling terminal */

#if __BSD_VISIBLE
/* Attempt to bypass buffer cache */
#define O_DIRECT	0x00010000
#endif

/* Defined by POSIX Extended API Set Part 2 */
#if __BSD_VISIBLE
#define	O_DIRECTORY	0x00020000	/* Fail if not directory */
#define	O_EXEC		0x00040000	/* Open for execute only */
#endif
#ifdef	_KERNEL
#define	FEXEC		O_EXEC
#endif

#if __POSIX_VISIBLE >= 200809
/* Defined by POSIX 1003.1-2008; BSD default, but reserve for future use. */
#define	O_TTY_INIT	0x00080000	/* Restore default termios attributes */

#define	O_CLOEXEC	0x00100000
#endif

/*
 * XXX missing O_DSYNC, O_RSYNC.
 */

#ifdef _KERNEL
/* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
#define	FFLAGS(oflags)	((oflags) + 1)
#define	OFLAGS(fflags)	((fflags) - 1)

/* bits to save after open */
#define	FMASK	(FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT|FEXEC)
/* bits settable by fcntl(F_SETFL, ...) */
#define	FCNTLFLAGS	(FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FRDAHEAD|O_DIRECT)

#if defined(COMPAT_FREEBSD7) || defined(COMPAT_FREEBSD6) || \
    defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4)
/*
 * Set by shm_open(3) in older libc's to get automatic MAP_ASYNC
 * behavior for POSIX shared memory objects (which are otherwise
 * implemented as plain files).
 */
#define	FPOSIXSHM	O_NOFOLLOW
#undef FCNTLFLAGS
#define	FCNTLFLAGS	(FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|FRDAHEAD| \
			 O_DIRECT)
#endif
#endif

/*
 * The O_* flags used to have only F* names, which were used in the kernel
 * and by fcntl.  We retain the F* names for the kernel f_flag field
 * and for backward compatibility for fcntl.  These flags are deprecated.
 */
#if __BSD_VISIBLE
#define	FAPPEND		O_APPEND	/* kernel/compat */
#define	FASYNC		O_ASYNC		/* kernel/compat */
#define	FFSYNC		O_FSYNC		/* kernel */
#define	FNONBLOCK	O_NONBLOCK	/* kernel */
#define	FNDELAY		O_NONBLOCK	/* compat */
#define	O_NDELAY	O_NONBLOCK	/* compat */
#endif

/*
 * We are out of bits in f_flag (which is a short).  However,
 * the flag bits not set in FMASK are only meaningful in the
 * initial open syscall.  Those bits can thus be given a
 * different meaning for fcntl(2).
 */
#if __BSD_VISIBLE
/* Read ahead */
#define	FRDAHEAD	O_CREAT
#endif

/* Defined by POSIX Extended API Set Part 2 */
#if __BSD_VISIBLE
/*
 * Magic value that specify the use of the current working directory
 * to determine the target of relative file paths in the openat() and
 * similar syscalls.
 */
#define	AT_FDCWD		-100

/*
 * Miscellaneous flags for the *at() syscalls.
 */
#define	AT_EACCESS		0x100	/* Check access using effective user and group ID */
#define	AT_SYMLINK_NOFOLLOW	0x200   /* Do not follow symbolic links */
#define	AT_SYMLINK_FOLLOW	0x400	/* Follow symbolic link */
#define	AT_REMOVEDIR		0x800	/* Remove directory instead of file */
#endif

/*
 * Constants used for fcntl(2)
 */

/* command values */
#define	F_DUPFD		0		/* duplicate file descriptor */
#define	F_GETFD		1		/* get file descriptor flags */
#define	F_SETFD		2		/* set file descriptor flags */
#define	F_GETFL		3		/* get file status flags */
#define	F_SETFL		4		/* set file status flags */
#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
#define	F_GETOWN	5		/* get SIGIO/SIGURG proc/pgrp */
#define F_SETOWN	6		/* set SIGIO/SIGURG proc/pgrp */
#endif
#define	F_OGETLK	7		/* get record locking information */
#define	F_OSETLK	8		/* set record locking information */
#define	F_OSETLKW	9		/* F_SETLK; wait if blocked */
#define	F_DUP2FD	10		/* duplicate file descriptor to arg */
#define	F_GETLK		11		/* get record locking information */
#define	F_SETLK		12		/* set record locking information */
#define	F_SETLKW	13		/* F_SETLK; wait if blocked */
#define	F_SETLK_REMOTE	14		/* debugging support for remote locks */
#define	F_READAHEAD	15		/* read ahead */
#define	F_RDAHEAD	16		/* Darwin compatible read ahead */

/* file descriptor flags (F_GETFD, F_SETFD) */
#define	FD_CLOEXEC	1		/* close-on-exec flag */

/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
#define	F_RDLCK		1		/* shared or read lock */
#define	F_UNLCK		2		/* unlock */
#define	F_WRLCK		3		/* exclusive or write lock */
#define	F_UNLCKSYS	4		/* purge locks for a given system ID */
#define	F_CANCEL	5		/* cancel an async lock request */
#ifdef _KERNEL
#define	F_WAIT		0x010		/* Wait until lock is granted */
#define	F_FLOCK		0x020	 	/* Use flock(2) semantics for lock */
#define	F_POSIX		0x040	 	/* Use POSIX semantics for lock */
#define	F_REMOTE	0x080		/* Lock owner is remote NFS client */
#define F_NOINTR	0x100		/* Ignore signals when waiting */
#endif

/*
 * Advisory file segment locking data type -
 * information passed to system by user
 */
struct flock {
	off_t	l_start;	/* starting offset */
	off_t	l_len;		/* len = 0 means until end of file */
	pid_t	l_pid;		/* lock owner */
	short	l_type;		/* lock type: read/write, etc. */
	short	l_whence;	/* type of l_start */
	int	l_sysid;	/* remote system id or zero for local */
};

/*
 * Old advisory file segment locking data type,
 * before adding l_sysid.
 */
struct oflock {
	off_t	l_start;	/* starting offset */
	off_t	l_len;		/* len = 0 means until end of file */
	pid_t	l_pid;		/* lock owner */
	short	l_type;		/* lock type: read/write, etc. */
	short	l_whence;	/* type of l_start */
};

#if __BSD_VISIBLE
/* lock operations for flock(2) */
#define	LOCK_SH		0x01		/* shared file lock */
#define	LOCK_EX		0x02		/* exclusive file lock */
#define	LOCK_NB		0x04		/* don't block when locking */
#define	LOCK_UN		0x08		/* unlock file */
#endif

/*
 * XXX missing posix_fadvise() and POSIX_FADV_* macros.
 */

#ifndef _KERNEL
__BEGIN_DECLS
int	open(const char *, int, ...);
int	creat(const char *, mode_t);
int	fcntl(int, int, ...);
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
int	openat(int, const char *, int, ...);
#endif
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
int	posix_fallocate(int, off_t, off_t);
#endif
#if __BSD_VISIBLE
int	flock(int, int);
#endif
__END_DECLS
#endif

#endif /* !_SYS_FCNTL_H_ */

repo_name: veiledmerc/mira

license: mit


code:
/*-
 * Copyright (C) 1992-1994,2001 by Joerg Wunsch, Dresden
 * 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(S) ``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(S) 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/sys/sys/fdcio.h 139825 2005-01-07 02:29:27Z imp $
 */

#ifndef	_MACHINE_IOCTL_FD_H_
#define	_MACHINE_IOCTL_FD_H_

#ifndef _KERNEL
#include <sys/types.h>
#endif
#include <sys/ioccom.h>

#define FD_FORMAT_VERSION 110	/* used to validate before formatting */
#define FD_MAX_NSEC 36		/* highest known number of spt - allow for */
				/* 2.88 MB drives */

struct fd_formb {
	int format_version;	/* == FD_FORMAT_VERSION */
	int cyl, head;
	int transfer_rate;	/* FDC_???KBPS */

	struct fd_form_data {
		/*
		 * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS
		 * it is hardware-dependent since it exactly
		 * matches the byte sequence to write to FDC
		 * during its `format track' operation
		 */
		u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */
		u_char nsecs;	/* must be <= FD_MAX_NSEC */
		u_char gaplen;	/* GAP 3 length; usually 84 */
		u_char fillbyte; /* usually 0xf6 */
		struct fd_idfield_data {
			/*
			 * data to write into id fields;
			 * for obscure formats, they mustn't match
			 * the real values (but mostly do)
			 */
			u_char cylno;	/* 0 thru 79 (or 39) */
			u_char headno;	/* 0, or 1 */
			u_char secno;	/* starting at 1! */
			u_char secsize;	/* usually 2 */
		} idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */
	} format_info;
};

/* make life easier */
# define fd_formb_secshift   format_info.secshift
# define fd_formb_nsecs      format_info.nsecs
# define fd_formb_gaplen     format_info.gaplen
# define fd_formb_fillbyte   format_info.fillbyte
/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */
# define fd_formb_cylno(i)   format_info.idfields[i].cylno
# define fd_formb_headno(i)  format_info.idfields[i].headno
# define fd_formb_secno(i)   format_info.idfields[i].secno
# define fd_formb_secsize(i) format_info.idfields[i].secsize

struct fd_type {
	int	sectrac;		/* sectors per track         */
	int	secsize;		/* size code for sectors     */
	int	datalen;		/* data len when secsize = 0 */
	int	gap;			/* gap len between sectors   */
	int	tracks;			/* total number of cylinders */
	int	size;			/* size of disk in sectors   */
	int	trans;			/* transfer speed code       */
	int	heads;			/* number of heads	     */
	int     f_gap;                  /* format gap len            */
	int     f_inter;                /* format interleave factor  */
	int	offset_side2;		/* offset of sectors on side2 */
	int	flags;			/* misc. features */
#define FL_MFM		0x0001		/* MFM recording */
#define FL_2STEP	0x0002		/* 2 steps between cylinders */
#define FL_PERPND	0x0004		/* perpendicular recording */
#define FL_AUTO		0x0008		/* autodetect format */
};

struct fdc_status {
	u_int	status[7];
};

/*
 * cyl and head are being passed into ioctl(FD_READID)
 * all four fields are being returned
 */
struct fdc_readid {
	u_char	cyl;		/* C - 0...79 */
	u_char	head;		/* H - 0...1 */
	u_char	sec;		/* R - 1...n */
	u_char	secshift;	/* N - log2(secsize / 128) */
};

/*
 * Diskette drive type, basically the same as stored in RTC on ISA
 * machines (see /sys/isa/rtc.h), but right-shifted by four bits.
 */
enum fd_drivetype {
	FDT_NONE, FDT_360K, FDT_12M, FDT_720K, FDT_144M, FDT_288M_1,
	FDT_288M
};

#define FD_FORM   _IOW('F', 61, struct fd_formb) /* format a track */
#define FD_GTYPE  _IOR('F', 62, struct fd_type)  /* get drive type */
#define FD_STYPE  _IOW('F', 63, struct fd_type)  /* set drive type */

#define FD_GOPTS  _IOR('F', 64, int) /* drive options, see below */
#define FD_SOPTS  _IOW('F', 65, int)

#ifdef PC98
#define FD_DEBUG  _IOW('F', 66, int)
#endif

#define FD_CLRERR _IO('F', 67)	/* clear error counter */

#define FD_READID _IOWR('F', 68, struct fdc_readid) /* read ID field */

/*
 * Obtain NE765 status registers.  Only successful if there is
 * a valid status stored in fdc->status[].
 */
#define FD_GSTAT  _IOR('F', 69, struct fdc_status)

#define FD_GDTYPE _IOR('F', 70, enum fd_drivetype) /* obtain drive type */

/* Options for FD_GOPTS/FD_SOPTS, cleared on device close */
#define FDOPT_NORETRY 0x0001	/* no retries on failure */
#define FDOPT_NOERRLOG 0x002	/* no "hard error" kernel log messages */
#define FDOPT_NOERROR 0x0004	/* do not indicate errors, caller will use
				   FD_GSTAT in order to obtain status */
#ifdef PC98
#define FDOPT_AUTOSEL 0x8000	/* read/only option: device performs media
				 * autoselection */
#endif

/*
 * Transfer rate definitions.  Used in the structures above.  They
 * represent the hardware encoding of bits 0 and 1 of the FDC control
 * register when writing to the register.
 * Transfer rates for FM encoding are half the values listed here
 * (but we currently don't support FM encoding).
 */
#define	FDC_500KBPS	0x00	/* 500KBPS MFM drive transfer rate */
#define	FDC_300KBPS	0x01	/* 300KBPS MFM drive transfer rate */
#define	FDC_250KBPS	0x02	/* 250KBPS MFM drive transfer rate */
#define	FDC_1MBPS	0x03	/* 1MPBS MFM drive transfer rate */

/*
 * Parameters for common formats
 *
 * See struct fd_type for layout.
 * XXX: Field 'size' must be calculated.
 * XXX: Fields 'f_inter' and 'offset_side2' are unused by kernel.
 *
 * XXX: These should really go in a /etc/floppycap colon separated file
 * XXX: but the kernel needs some of them for proper defaults and it would
 * XXX: should have been done 20 years ago to make sense.
 */
#ifdef PC98
#define FDF_3_1722 21,2,0xFF,0x04,82,0,2,2,0x0C,2,0,FL_MFM
#define FDF_3_1476 18,2,0xFF,0x1B,82,0,2,2,0x54,1,0,FL_MFM
#define FDF_3_1440 18,2,0xFF,0x1B,80,0,2,2,0x54,1,0,FL_MFM
#define FDF_3_1200 15,2,0xFF,0x1B,80,0,0,2,0x54,1,0,FL_MFM
#define FDF_3_820  10,2,0xFF,0x10,82,0,1,2,0x30,1,0,FL_MFM
#define FDF_3_800  10,2,0xFF,0x10,80,0,1,2,0x30,1,0,FL_MFM
#define FDF_3_720   9,2,0xFF,0x20,80,0,1,2,0x50,1,0,FL_MFM
#define FDF_3_360   9,2,0xFF,0x20,40,0,1,2,0x50,1,0,FL_MFM|FL_2STEP
#define FDF_3_640   8,2,0xFF,0x2A,80,0,1,2,0x50,1,0,FL_MFM
#define FDF_3_1230  8,3,0xFF,0x35,77,0,0,2,0x74,1,0,FL_MFM
#define FDF_3_1280  8,3,0xFF,0x35,80,0,0,2,0x74,1,0,FL_MFM
#define FDF_3_1480  9,3,0xFF,0x35,82,0,0,2,0x47,1,0,FL_MFM
#define FDF_3_1640 10,3,0xFF,0x1B,82,0,2,2,0x54,1,0,FL_MFM
#define FDF_5_1200 15,2,0xFF,0x1B,80,0,0,2,0x54,1,0,FL_MFM
#define FDF_5_820  10,2,0xFF,0x10,82,0,1,2,0x30,1,0,FL_MFM
#define FDF_5_800  10,2,0xFF,0x10,80,0,1,2,0x30,1,0,FL_MFM
#define FDF_5_720   9,2,0xFF,0x20,80,0,1,2,0x50,1,0,FL_MFM
#define FDF_5_360   9,2,0xFF,0x20,40,0,1,2,0x50,1,0,FL_MFM|FL_2STEP
#define FDF_5_640   8,2,0xFF,0x2A,80,0,1,2,0x50,1,0,FL_MFM
#define FDF_5_1230  8,3,0xFF,0x35,77,0,0,2,0x74,1,0,FL_MFM
#define FDF_5_1280  8,3,0xFF,0x35,80,0,0,2,0x74,1,0,FL_MFM
#else /* PC98 */
#define FDF_3_2880 36,2,0xFF,0x1B,80,0,FDC_1MBPS,002,0x4C,1,1,FL_MFM|FL_PERPND
#define FDF_3_1722 21,2,0xFF,0x04,82,0,FDC_500KBPS,2,0x0C,2,0,FL_MFM
#define FDF_3_1476 18,2,0xFF,0x1B,82,0,FDC_500KBPS,2,0x6C,1,0,FL_MFM
#define FDF_3_1440 18,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x6C,1,0,FL_MFM
#define FDF_3_1200 15,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x54,1,0,FL_MFM
#define FDF_3_820  10,2,0xFF,0x10,82,0,FDC_250KBPS,2,0x2e,1,0,FL_MFM
#define FDF_3_800  10,2,0xFF,0x10,80,0,FDC_250KBPS,2,0x2e,1,0,FL_MFM
#define FDF_3_720   9,2,0xFF,0x20,80,0,FDC_250KBPS,2,0x50,1,0,FL_MFM
#define FDF_5_1480 18,2,0xFF,0x02,82,0,FDC_500KBPS,2,0x02,2,0,FL_MFM
#define FDF_5_1440 18,2,0xFF,0x02,80,0,FDC_500KBPS,2,0x02,2,0,FL_MFM
#define FDF_5_1230  8,3,0xFF,0x35,77,0,FDC_500KBPS,2,0x74,1,0,FL_MFM
#define FDF_5_1200 15,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x54,1,0,FL_MFM
#define FDF_5_820  10,2,0xFF,0x10,82,0,FDC_300KBPS,2,0x2e,1,0,FL_MFM
#define FDF_5_800  10,2,0xFF,0x10,80,0,FDC_300KBPS,2,0x2e,1,0,FL_MFM
#define FDF_5_720   9,2,0xFF,0x20,80,0,FDC_300KBPS,2,0x50,1,0,FL_MFM
#define FDF_5_640   8,2,0xFF,0x2A,80,0,FDC_300KBPS,2,0x50,1,0,FL_MFM
#define FDF_5_360   9,2,0xFF,0x23,40,0,FDC_300KBPS,2,0x50,1,0,FL_MFM
/* XXX:                      0x2a ? */
#endif

#endif /* !_MACHINE_IOCTL_FD_H_ */


code:
/*-
 * Copyright (c) 1982, 1986, 1989, 1993
 *	The Regents of the University of California.  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.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * 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.
 *
 *	@(#)file.h	8.3 (Berkeley) 1/9/95
 * $FreeBSD: release/9.0.0/sys/sys/file.h 224987 2011-08-18 22:51:30Z jonathan $
 */

#ifndef _SYS_FILE_H_
#define	_SYS_FILE_H_

#ifndef _KERNEL
#include <sys/types.h> /* XXX */
#include <sys/fcntl.h>
#include <sys/unistd.h>
#else
#include <sys/queue.h>
#include <sys/refcount.h>
#include <sys/_lock.h>
#include <sys/_mutex.h>

struct stat;
struct thread;
struct uio;
struct knote;
struct vnode;
struct socket;

#endif /* _KERNEL */

#define	DTYPE_VNODE	1	/* file */
#define	DTYPE_SOCKET	2	/* communications endpoint */
#define	DTYPE_PIPE	3	/* pipe */
#define	DTYPE_FIFO	4	/* fifo (named pipe) */
#define	DTYPE_KQUEUE	5	/* event queue */
#define	DTYPE_CRYPTO	6	/* crypto */
#define	DTYPE_MQUEUE	7	/* posix message queue */
#define	DTYPE_SHM	8	/* swap-backed shared memory */
#define	DTYPE_SEM	9	/* posix semaphore */
#define	DTYPE_PTS	10	/* pseudo teletype master device */
#define	DTYPE_DEV	11	/* Device specific fd type */
#define	DTYPE_CAPABILITY	12	/* capability */
#define	DTYPE_PROCDESC	13	/* process descriptor */

#ifdef _KERNEL

struct file;
struct ucred;

typedef int fo_rdwr_t(struct file *fp, struct uio *uio,
		    struct ucred *active_cred, int flags,
		    struct thread *td);
#define	FOF_OFFSET	1	/* Use the offset in uio argument */
typedef	int fo_truncate_t(struct file *fp, off_t length,
		    struct ucred *active_cred, struct thread *td);
typedef	int fo_ioctl_t(struct file *fp, u_long com, void *data,
		    struct ucred *active_cred, struct thread *td);
typedef	int fo_poll_t(struct file *fp, int events,
		    struct ucred *active_cred, struct thread *td);
typedef	int fo_kqfilter_t(struct file *fp, struct knote *kn);
typedef	int fo_stat_t(struct file *fp, struct stat *sb,
		    struct ucred *active_cred, struct thread *td);
typedef	int fo_close_t(struct file *fp, struct thread *td);
typedef	int fo_chmod_t(struct file *fp, mode_t mode,
		    struct ucred *active_cred, struct thread *td);
typedef	int fo_chown_t(struct file *fp, uid_t uid, gid_t gid,
		    struct ucred *active_cred, struct thread *td);
typedef	int fo_flags_t;

struct fileops {
	fo_rdwr_t	*fo_read;
	fo_rdwr_t	*fo_write;
	fo_truncate_t	*fo_truncate;
	fo_ioctl_t	*fo_ioctl;
	fo_poll_t	*fo_poll;
	fo_kqfilter_t	*fo_kqfilter;
	fo_stat_t	*fo_stat;
	fo_close_t	*fo_close;
	fo_chmod_t	*fo_chmod;
	fo_chown_t	*fo_chown;
	fo_flags_t	fo_flags;	/* DFLAG_* below */
};

#define DFLAG_PASSABLE	0x01	/* may be passed via unix sockets. */
#define DFLAG_SEEKABLE	0x02	/* seekable / nonsequential */
#endif /* _KERNEL */

#if defined(_KERNEL) || defined(_WANT_FILE)
/*
 * Kernel descriptor table.
 * One entry for each open kernel vnode and socket.
 *
 * Below is the list of locks that protects members in struct file.
 *
 * (f) protected with mtx_lock(mtx_pool_find(fp))
 * (d) cdevpriv_mtx
 * none	not locked
 */

/*
PlayStation 4 sizes
sizeof(struct file)
1.01 - 1.76 = 0x58
2.00 - 7.00 = 0x68
*/
struct file {
	void		*f_data;	/* file descriptor specific data */
	struct fileops	*f_ops;		/* File operations */
	struct ucred	*f_cred;	/* associated credentials. */
	struct vnode 	*f_vnode;	/* NULL or applicable vnode */
	short		f_type;		/* descriptor type */
	short		f_vnread_flags; /* (f) Sleep lock for f_offset */
	volatile u_int	f_flag;		/* see fcntl.h */
	volatile u_int 	f_count;	/* reference count */
	/*
	 *  DTYPE_VNODE specific fields.
	 */
	int		f_seqcount;	/* Count of sequential accesses. */
	off_t		f_nextoff;	/* next expected read/write offset. */
	struct cdev_privdata *f_cdevpriv; /* (d) Private data for the cdev. */
	/*
	 *  DFLAG_SEEKABLE specific fields
	 */
	off_t		f_offset;
	/*
	 * Mandatory Access control information.
	 */
	void		*f_label;	/* Place-holder for MAC label. */
};

#define	FOFFSET_LOCKED       0x1
#define	FOFFSET_LOCK_WAITING 0x2

#endif /* _KERNEL || _WANT_FILE */

/*
 * Userland version of struct file, for sysctl
 */
struct xfile {
	size_t	xf_size;	/* size of struct xfile */
	pid_t	xf_pid;		/* owning process */
	uid_t	xf_uid;		/* effective uid of owning process */
	int	xf_fd;		/* descriptor number */
	void	*xf_file;	/* address of struct file */
	short	xf_type;	/* descriptor type */
	int	xf_count;	/* reference count */
	int	xf_msgcount;	/* references from message queue */
	off_t	xf_offset;	/* file offset */
	void	*xf_data;	/* file descriptor specific data */
	void	*xf_vnode;	/* vnode pointer */
	u_int	xf_flag;	/* flags (see fcntl.h) */
};

#ifdef _KERNEL

#ifdef MALLOC_DECLARE
MALLOC_DECLARE(M_FILE);
#endif

extern struct fileops vnops;
extern struct fileops badfileops;
extern struct fileops socketops;
extern int maxfiles;		/* kernel limit on number of open files */
extern int maxfilesperproc;	/* per process limit on number of open files */
extern volatile int openfiles;	/* actual number of open files */

int fget(struct thread *td, int fd, cap_rights_t rights, struct file **fpp);
int fget_mmap(struct thread *td, int fd, cap_rights_t rights,
    u_char *maxprotp, struct file **fpp);
int fget_read(struct thread *td, int fd, cap_rights_t rights,
    struct file **fpp);
int fget_write(struct thread *td, int fd, cap_rights_t rights,
    struct file **fpp);
int fgetcap(struct thread *td, int fd, struct file **fpp);
int _fdrop(struct file *fp, struct thread *td);

/*
 * The socket operations are used a couple of places.
 * XXX: This is wrong, they should go through the operations vector for
 * XXX: sockets instead of going directly for the individual functions. /phk
 */
fo_rdwr_t	soo_read;
fo_rdwr_t	soo_write;
fo_truncate_t	soo_truncate;
fo_ioctl_t	soo_ioctl;
fo_poll_t	soo_poll;
fo_kqfilter_t	soo_kqfilter;
fo_stat_t	soo_stat;
fo_close_t	soo_close;

fo_chmod_t	invfo_chmod;
fo_chown_t	invfo_chown;

void finit(struct file *, u_int, short, void *, struct fileops *);
int fgetvp(struct thread *td, int fd, cap_rights_t rights, struct vnode **vpp);
int fgetvp_rights(struct thread *td, int fd, cap_rights_t need,
    cap_rights_t *have, struct vnode **vpp);
int fgetvp_read(struct thread *td, int fd, cap_rights_t rights,
    struct vnode **vpp);
int fgetvp_write(struct thread *td, int fd, cap_rights_t rights,
    struct vnode **vpp);

int fgetsock(struct thread *td, int fd, cap_rights_t rights,
    struct socket **spp, u_int *fflagp);
void fputsock(struct socket *sp);

static __inline int
_fnoop(void)
{

	return (0);
}

#define	fhold(fp)							\
	(refcount_acquire(&(fp)->f_count))
#define	fdrop(fp, td)							\
	(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop())

static __inline fo_rdwr_t	fo_read;
static __inline fo_rdwr_t	fo_write;
static __inline fo_truncate_t	fo_truncate;
static __inline fo_ioctl_t	fo_ioctl;
static __inline fo_poll_t	fo_poll;
static __inline fo_kqfilter_t	fo_kqfilter;
static __inline fo_stat_t	fo_stat;
static __inline fo_close_t	fo_close;
static __inline fo_chmod_t	fo_chmod;
static __inline fo_chown_t	fo_chown;

static __inline int
fo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
    int flags, struct thread *td)
{

	return ((*fp->f_ops->fo_read)(fp, uio, active_cred, flags, td));
}

static __inline int
fo_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
    int flags, struct thread *td)
{

	return ((*fp->f_ops->fo_write)(fp, uio, active_cred, flags, td));
}

static __inline int
fo_truncate(struct file *fp, off_t length, struct ucred *active_cred,
    struct thread *td)
{

	return ((*fp->f_ops->fo_truncate)(fp, length, active_cred, td));
}

static __inline int
fo_ioctl(struct file *fp, u_long com, void *data, struct ucred *active_cred,
    struct thread *td)
{

	return ((*fp->f_ops->fo_ioctl)(fp, com, data, active_cred, td));
}

static __inline int
fo_poll(struct file *fp, int events, struct ucred *active_cred,
    struct thread *td)
{

	return ((*fp->f_ops->fo_poll)(fp, events, active_cred, td));
}

static __inline int
fo_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
    struct thread *td)
{

	return ((*fp->f_ops->fo_stat)(fp, sb, active_cred, td));
}

static __inline int
fo_close(struct file *fp, struct thread *td)
{

	return ((*fp->f_ops->fo_close)(fp, td));
}

static __inline int
fo_kqfilter(struct file *fp, struct knote *kn)
{

	return ((*fp->f_ops->fo_kqfilter)(fp, kn));
}

static __inline int
fo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred,
    struct thread *td)
{

	return ((*fp->f_ops->fo_chmod)(fp, mode, active_cred, td));
}

static __inline int
fo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred,
    struct thread *td)
{

	return ((*fp->f_ops->fo_chown)(fp, uid, gid, active_cred, td));
}

#endif /* _KERNEL */

#endif /* !SYS_FILE_H */


code:
/*-
 * Copyright (c) 1990, 1993
 *	The Regents of the University of California.  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.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * 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.
 *
 *	@(#)filedesc.h	8.1 (Berkeley) 6/2/93
 * $FreeBSD: release/9.0.0/sys/sys/filedesc.h 224778 2011-08-11 12:30:23Z rwatson $
 */

#ifndef _SYS_FILEDESC_H_
#define	_SYS_FILEDESC_H_

#include <sys/queue.h>
#include <sys/event.h>
#include <sys/lock.h>
#include <sys/priority.h>
#include <sys/sx.h>

#include <machine/_limits.h>

/*
 * This structure is used for the management of descriptors.  It may be
 * shared by multiple processes.
 */
#define NDSLOTTYPE	u_long

struct filedesc {
	struct	file **fd_ofiles;	/* file structures for open files */
	char	*fd_ofileflags;		/* per-process open file flags */
	struct	vnode *fd_cdir;		/* current directory */
	struct	vnode *fd_rdir;		/* root directory */
	struct	vnode *fd_jdir;		/* jail root directory */
	int	fd_nfiles;		/* number of open files allocated */
	NDSLOTTYPE *fd_map;		/* bitmap of free fds */
	int	fd_lastfile;		/* high-water mark of fd_ofiles */
	int	fd_freefile;		/* approx. next free file */
	u_short	fd_cmask;		/* mask for file creation */
	u_short	fd_refcnt;		/* thread reference count */
	u_short	fd_holdcnt;		/* hold count on structure + mutex */
	struct	sx fd_sx;		/* protects members of this struct */
	struct	kqlist fd_kqlist;	/* list of kqueues on this filedesc */
	int	fd_holdleaderscount;	/* block fdfree() for shared close() */
	int	fd_holdleaderswakeup;	/* fdfree() needs wakeup */
};

/*
 * Structure to keep track of (process leader, struct fildedesc) tuples.
 * Each process has a pointer to such a structure when detailed tracking
 * is needed, e.g., when rfork(RFPROC | RFMEM) causes a file descriptor
 * table to be shared by processes having different "p_leader" pointers
 * and thus distinct POSIX style locks.
 *
 * fdl_refcount and fdl_holdcount are protected by struct filedesc mtx.
 */
struct filedesc_to_leader {
	int		fdl_refcount;	/* references from struct proc */
	int		fdl_holdcount;	/* temporary hold during closef */
	int		fdl_wakeup;	/* fdfree() waits on closef() */
	struct proc	*fdl_leader;	/* owner of POSIX locks */
	/* Circular list: */
	struct filedesc_to_leader *fdl_prev;
	struct filedesc_to_leader *fdl_next;
};

/*
 * Per-process open flags.
 */
#define	UF_EXCLOSE 	0x01		/* auto-close on exec */

#ifdef _KERNEL

/* Lock a file descriptor table. */
#define	FILEDESC_LOCK_INIT(fdp)	sx_init(&(fdp)->fd_sx, "filedesc structure")
#define	FILEDESC_LOCK_DESTROY(fdp)	sx_destroy(&(fdp)->fd_sx)
#define	FILEDESC_LOCK(fdp)	(&(fdp)->fd_sx)
#define	FILEDESC_XLOCK(fdp)	sx_xlock(&(fdp)->fd_sx)
#define	FILEDESC_XUNLOCK(fdp)	sx_xunlock(&(fdp)->fd_sx)
#define	FILEDESC_SLOCK(fdp)	sx_slock(&(fdp)->fd_sx)
#define	FILEDESC_SUNLOCK(fdp)	sx_sunlock(&(fdp)->fd_sx)

#define	FILEDESC_LOCK_ASSERT(fdp)	sx_assert(&(fdp)->fd_sx, SX_LOCKED | \
					    SX_NOTRECURSED)
#define	FILEDESC_XLOCK_ASSERT(fdp)	sx_assert(&(fdp)->fd_sx, SX_XLOCKED | \
					    SX_NOTRECURSED)

struct thread;

int	closef(struct file *fp, struct thread *td);
int	dupfdopen(struct thread *td, struct filedesc *fdp, int indx, int dfd,
	    int mode, int error);
int	falloc(struct thread *td, struct file **resultfp, int *resultfd,
	    int flags);
int	falloc_noinstall(struct thread *td, struct file **resultfp);
int	finstall(struct thread *td, struct file *fp, int *resultfp, int flags);
int	fdalloc(struct thread *td, int minfd, int *result);
int	fdavail(struct thread *td, int n);
int	fdcheckstd(struct thread *td);
void	fdclose(struct filedesc *fdp, struct file *fp, int idx, struct thread *td);
void	fdcloseexec(struct thread *td);
struct	filedesc *fdcopy(struct filedesc *fdp);
void	fdunshare(struct proc *p, struct thread *td);
void	fdfree(struct thread *td);
struct	filedesc *fdinit(struct filedesc *fdp);
struct	filedesc *fdshare(struct filedesc *fdp);
struct filedesc_to_leader *
	filedesc_to_leader_alloc(struct filedesc_to_leader *old,
	    struct filedesc *fdp, struct proc *leader);
int	getvnode(struct filedesc *fdp, int fd, cap_rights_t rights,
	    struct file **fpp);
void	mountcheckdirs(struct vnode *olddp, struct vnode *newdp);
void	setugidsafety(struct thread *td);

/* Return a referenced file from an unlocked descriptor. */
struct file *fget_unlocked(struct filedesc *fdp, int fd);

/* Requires a FILEDESC_{S,X}LOCK held and returns without a ref. */
static __inline struct file *
fget_locked(struct filedesc *fdp, int fd)
{

	return (fd < 0 || fd >= fdp->fd_nfiles ? NULL : fdp->fd_ofiles[fd]);
}

#endif /* _KERNEL */

#endif /* !_SYS_FILEDESC_H_ */


code:
/*-
 * Copyright (c) 1982, 1986, 1990, 1993, 1994
 *	The Regents of the University of California.  All rights reserved.
 * (c) UNIX System Laboratories, Inc.
 * All or some portions of this file are derived from material licensed
 * to the University of California by American Telephone and Telegraph
 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
 * the permission of UNIX System Laboratories, Inc.
 *
 * 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.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * 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.
 *
 *	@(#)filio.h	8.1 (Berkeley) 3/28/94
 * $FreeBSD: release/9.0.0/sys/sys/filio.h 195191 2009-06-30 13:38:49Z emaste $
 */

#ifndef	_SYS_FILIO_H_
#define	_SYS_FILIO_H_

#include <sys/ioccom.h>

/* Generic file-descriptor ioctl's. */
#define	FIOCLEX		 _IO('f', 1)		/* set close on exec on fd */
#define	FIONCLEX	 _IO('f', 2)		/* remove close on exec */
#define	FIONREAD	_IOR('f', 127, int)	/* get # bytes to read */
#define	FIONBIO		_IOW('f', 126, int)	/* set/clear non-blocking i/o */
#define	FIOASYNC	_IOW('f', 125, int)	/* set/clear async i/o */
#define	FIOSETOWN	_IOW('f', 124, int)	/* set owner */
#define	FIOGETOWN	_IOR('f', 123, int)	/* get owner */
#define	FIODTYPE	_IOR('f', 122, int)	/* get d_flags type part */
#define	FIOGETLBA	_IOR('f', 121, int)	/* get start blk # */
struct fiodgname_arg {
	int	len;
	void	*buf;
};
#define	FIODGNAME	_IOW('f', 120, struct fiodgname_arg) /* get dev. name */
#define	FIONWRITE	_IOR('f', 119, int)	/* get # bytes (yet) to write */
#define	FIONSPACE	_IOR('f', 118, int)	/* get space in send queue */
/* Handle lseek SEEK_DATA and SEEK_HOLE for holey file knowledge. */
#define	FIOSEEKDATA	_IOWR('f', 97, off_t)	/* SEEK_DATA */
#define	FIOSEEKHOLE	_IOWR('f', 98, off_t)	/* SEEK_HOLE */

#endif /* !_SYS_FILIO_H_ */


code:
/*-
 * Copyright (c) 2005, Sam Leffler <sam@errno.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 unmodified, 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 ``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/sys/sys/firmware.h 166756 2007-02-15 17:21:31Z luigi $
 */
#ifndef _SYS_FIRMWARE_H_
#define _SYS_FIRMWARE_H_
/*
 * Loadable firmware support.
 *
 * The firmware abstraction provides an interface for loading firmware
 * images into the kernel and making them available to clients.
 *
 * Firmware images are usually embedded in kernel loadable modules that can
 * be loaded on-demand or pre-loaded as desired.  Modules may contain
 * one or more firmware images that are stored as opaque data arrays
 * and registered with a unique string name. Clients request
 * firmware by name, and are returned a struct firmware * below on success.
 * The kernel keeps track of references to firmware images to allow/prevent
 * module/data unload.
 *
 * When multiple images are stored in one module, the first image is
 * treated as the master with the other images holding references
 * to it.  This means that to unload the module each dependent/subimage
 * must first have its references removed.
 * In order for automatic loading to work, the master image must have
 * the same name as the module it is embedded into.
 */
struct firmware {
	const char	*name;		/* system-wide name */
	const void	*data;		/* location of image */
	size_t		 datasize;	/* size of image in bytes */
	unsigned int	 version;	/* version of the image */
};

const struct firmware	*firmware_register(const char *,
	const void *, size_t, unsigned int, const struct firmware *);
int	 firmware_unregister(const char *);
const struct firmware *firmware_get(const char *);
#define	FIRMWARE_UNLOAD		0x0001	/* unload if unreferenced */
void		 firmware_put(const struct firmware *, int);
#endif /* _SYS_FIRMWARE_H_ */


code:
/*-
 * Fowler / Noll / Vo Hash (FNV Hash)
 * http://www.isthe.com/chongo/tech/comp/fnv/
 *
 * This is an implementation of the algorithms posted above.
 * This file is placed in the public domain by Peter Wemm.
 *
 * $FreeBSD: release/9.0.0/sys/sys/fnv_hash.h 139825 2005-01-07 02:29:27Z imp $
 */

typedef u_int32_t Fnv32_t;
typedef u_int64_t Fnv64_t;

#define FNV1_32_INIT ((Fnv32_t) 33554467UL)
#define FNV1_64_INIT ((Fnv64_t) 0xcbf29ce484222325ULL)

#define FNV_32_PRIME ((Fnv32_t) 0x01000193UL)
#define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL)

static __inline Fnv32_t
fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
{
	const u_int8_t *s = (const u_int8_t *)buf;

	while (len-- != 0) {
		hval *= FNV_32_PRIME;
		hval ^= *s++;
	}
	return hval;
}

static __inline Fnv32_t
fnv_32_str(const char *str, Fnv32_t hval)
{
	const u_int8_t *s = (const u_int8_t *)str;
	Fnv32_t c;

	while ((c = *s++) != 0) {
		hval *= FNV_32_PRIME;
		hval ^= c;
	}
	return hval;
}

static __inline Fnv64_t
fnv_64_buf(const void *buf, size_t len, Fnv64_t hval)
{
	const u_int8_t *s = (const u_int8_t *)buf;

	while (len-- != 0) {
		hval *= FNV_64_PRIME;
		hval ^= *s++;
	}
	return hval;
}

static __inline Fnv64_t
fnv_64_str(const char *str, Fnv64_t hval)
{
	const u_int8_t *s = (const u_int8_t *)str;
	u_register_t c;		 /* 32 bit on i386, 64 bit on alpha,ia64 */

	while ((c = *s++) != 0) {
		hval *= FNV_64_PRIME;
		hval ^= c;
	}
	return hval;
}


code:
/*-
 * Copyright (c) 1982, 1986, 1992, 1993
 *	The Regents of the University of California.  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.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * 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.
 *
 *	@(#)gmon.h	8.2 (Berkeley) 1/4/94
 * $FreeBSD: release/9.0.0/sys/sys/gmon.h 157268 2006-03-29 18:17:03Z jhb $
 */

#ifndef _SYS_GMON_H_
#define _SYS_GMON_H_

#include <machine/profile.h>

/*
 * Structure prepended to gmon.out profiling data file.
 */
struct gmonhdr {
	u_long	lpc;		/* base pc address of sample buffer */
	u_long	hpc;		/* max pc address of sampled buffer */
	int	ncnt;		/* size of sample buffer (plus this header) */
	int	version;	/* version number */
	int	profrate;	/* profiling clock rate */
	int	histcounter_type; /* size (in bits) and sign of HISTCOUNTER */
	int	spare[2];	/* reserved */
};
#define GMONVERSION	0x00051879

/*
 * Type of histogram counters used in the kernel.
 */
#ifdef GPROF4
#define	HISTCOUNTER	int64_t
#else
#define	HISTCOUNTER	unsigned short
#endif

/*
 * Fraction of text space to allocate for histogram counters.
 * We allocate counters at the same or higher density as function
 * addresses, so that each counter belongs to a unique function.
 * A lower density of counters would give less resolution but a
 * higher density would be wasted.
 */
#define	HISTFRACTION	(FUNCTION_ALIGNMENT / sizeof(HISTCOUNTER) == 0 \
			 ? 1 : FUNCTION_ALIGNMENT / sizeof(HISTCOUNTER))

/*
 * Fraction of text space to allocate for from hash buckets.
 * The value of HASHFRACTION is based on the minimum number of bytes
 * of separation between two subroutine call points in the object code.
 * Given MIN_SUBR_SEPARATION bytes of separation the value of
 * HASHFRACTION is calculated as:
 *
 *	HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
 *
 * For example, on the VAX, the shortest two call sequence is:
 *
 *	calls	$0,(r0)
 *	calls	$0,(r0)
 *
 * which is separated by only three bytes, thus HASHFRACTION is
 * calculated as:
 *
 *	HASHFRACTION = 3 / (2 * 2 - 1) = 1
 *
 * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
 * is less than three, this algorithm will not work!
 *
 * In practice, however, call instructions are rarely at a minimal
 * distance.  Hence, we will define HASHFRACTION to be 2 across all
 * architectures.  This saves a reasonable amount of space for
 * profiling data structures without (in practice) sacrificing
 * any granularity.
 */
/*
 * XXX I think the above analysis completely misses the point.  I think
 * the point is that addresses in different functions must hash to
 * different values.  Since the hash is essentially division by
 * sizeof(unsigned short), the correct formula is:
 *
 * 	HASHFRACTION = MIN_FUNCTION_ALIGNMENT / sizeof(unsigned short)
 *
 * Note that he unsigned short here has nothing to do with the one for
 * HISTFRACTION.
 *
 * Hash collisions from a two call sequence don't matter.  They get
 * handled like collisions for calls to different addresses from the
 * same address through a function pointer.
 */
#define	HASHFRACTION	(FUNCTION_ALIGNMENT / sizeof(unsigned short) == 0 \
			 ? 1 : FUNCTION_ALIGNMENT / sizeof(unsigned short))

/*
 * percent of text space to allocate for tostructs with a minimum.
 */
#define ARCDENSITY	2
#define MINARCS		50

/*
 * Limit on the number of arcs to so that arc numbers can be stored in
 * `*froms' and stored and incremented without overflow in links.
 */
#define MAXARCS		(((u_long)1 << (8 * sizeof(u_short))) - 2)

struct tostruct {
	u_long	selfpc;
	long	count;
	u_short	link;
	u_short pad;
};

/*
 * a raw arc, with pointers to the calling site and
 * the called site and a count.
 */
struct rawarc {
	u_long	raw_frompc;
	u_long	raw_selfpc;
	long	raw_count;
};

/*
 * general rounding functions.
 */
#define ROUNDDOWN(x,y)	rounddown(x,y)
#define ROUNDUP(x,y)	roundup(x,y)

/*
 * The profiling data structures are housed in this structure.
 */
struct gmonparam {
	int		state;
	HISTCOUNTER	*kcount;
	u_long		kcountsize;
	u_short		*froms;
	u_long		fromssize;
	struct tostruct	*tos;
	u_long		tossize;
	long		tolimit;
	uintfptr_t	lowpc;
	uintfptr_t	highpc;
	u_long		textsize;
	u_long		hashfraction;
	int		profrate;	/* XXX wrong type to match gmonhdr */
	HISTCOUNTER	*cputime_count;
	int		cputime_overhead;
	HISTCOUNTER	*mcount_count;
	int		mcount_overhead;
	int		mcount_post_overhead;
	int		mcount_pre_overhead;
	HISTCOUNTER	*mexitcount_count;
	int		mexitcount_overhead;
	int		mexitcount_post_overhead;
	int		mexitcount_pre_overhead;
	int		histcounter_type;
};
extern struct gmonparam _gmonparam;

/*
 * Possible states of profiling.
 */
#define	GMON_PROF_ON	0
#define	GMON_PROF_BUSY	1
#define	GMON_PROF_ERROR	2
#define	GMON_PROF_OFF	3
#define	GMON_PROF_HIRES	4

/*
 * Sysctl definitions for extracting profiling information from the kernel.
 */
#define	GPROF_STATE	0	/* int: profiling enabling variable */
#define	GPROF_COUNT	1	/* struct: profile tick count buffer */
#define	GPROF_FROMS	2	/* struct: from location hash bucket */
#define	GPROF_TOS	3	/* struct: destination/count structure */
#define	GPROF_GMONPARAM	4	/* struct: profiling parameters (see above) */

#ifdef _KERNEL

#define	KCOUNT(p,index) \
	((p)->kcount[(index) / (HISTFRACTION * sizeof(HISTCOUNTER))])
#define	PC_TO_I(p, pc)	((uintfptr_t)(pc) - (uintfptr_t)(p)->lowpc)

#ifdef GUPROF

#define	CALIB_SCALE	1000

extern int	cputime_bias;

int	cputime(void);
void	nullfunc_loop_profiled(void);
void	nullfunc_profiled(void);
void	startguprof(struct gmonparam *p);
void	stopguprof(struct gmonparam *p);

#else /* !GUPROF */

#define	startguprof(p)
#define	stopguprof(p)

#endif /* GUPROF */

void	empty_loop(void);
void	kmupetext(uintfptr_t nhighpc);
void	mexitcount(uintfptr_t selfpc);
void	nullfunc(void);
void	nullfunc_loop(void);

#else /* !_KERNEL */

#include <sys/cdefs.h>

__BEGIN_DECLS
void	moncontrol(int);
void	monstartup(u_long, u_long);
__END_DECLS

#endif /* _KERNEL */

#endif /* !_SYS_GMON_H_ */


code:
/* $NetBSD: gpio.h,v 1.7 2009/09/25 20:27:50 mbalmer Exp $ */
/*	$OpenBSD: gpio.h,v 1.7 2008/11/26 14:51:20 mbalmer Exp $	*/
/*-
 * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@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 unmodified, 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/sys/sys/gpio.h 213237 2010-09-28 03:24:53Z gonzo $
 *
 */

/*
 * Copyright (c) 2009 Marc Balmer <marc@msys.ch>
 * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef __GPIO_H__
#define __GPIO_H__

#include <sys/ioccom.h>

/* GPIO pin states */
#define GPIO_PIN_LOW		0x00	/* low level (logical 0) */
#define GPIO_PIN_HIGH		0x01	/* high level (logical 1) */

/* Max name length of a pin */
#define GPIOMAXNAME		64

/* GPIO pin configuration flags */
#define GPIO_PIN_INPUT		0x0001	/* input direction */
#define GPIO_PIN_OUTPUT		0x0002	/* output direction */
#define GPIO_PIN_OPENDRAIN	0x0004	/* open-drain output */
#define GPIO_PIN_PUSHPULL	0x0008	/* push-pull output */
#define GPIO_PIN_TRISTATE	0x0010	/* output disabled */
#define GPIO_PIN_PULLUP		0x0020	/* internal pull-up enabled */
#define GPIO_PIN_PULLDOWN	0x0040	/* internal pull-down enabled */
#define GPIO_PIN_INVIN		0x0080	/* invert input */
#define GPIO_PIN_INVOUT		0x0100	/* invert output */
#define GPIO_PIN_PULSATE	0x0200	/* pulsate in hardware */

struct gpio_pin {
	uint32_t gp_pin;			/* pin number */
	char gp_name[GPIOMAXNAME];		/* human-readable name */
	uint32_t gp_caps;			/* capabilities */
	uint32_t gp_flags;			/* current flags */
};

/* GPIO pin request (read/write/toggle) */
struct gpio_req {
	uint32_t gp_pin;			/* pin number */
	uint32_t gp_value;			/* value */
};

/*
 * ioctls
 */
#define GPIOMAXPIN		_IOR('G', 0, int)
#define	GPIOGETCONFIG		_IOWR('G', 1, struct gpio_pin)
#define	GPIOSETCONFIG		_IOW('G', 2, struct gpio_pin)
#define	GPIOGET			_IOWR('G', 3, struct gpio_req)
#define	GPIOSET			_IOW('G', 4, struct gpio_req)
#define	GPIOTOGGLE		_IOWR('G', 5, struct gpio_req)

#endif /* __GPIO_H__ */


code:
/*-
 * Copyright (c) 2002 Marcel Moolenaar
 * 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 ``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/sys/sys/gpt.h 218014 2011-01-28 11:13:01Z ae $
 */

#ifndef _SYS_GPT_H_
#define	_SYS_GPT_H_

#include <sys/uuid.h>

struct gpt_hdr {
	char		hdr_sig[8];
#define	GPT_HDR_SIG		"EFI PART"
	uint32_t	hdr_revision;
#define	GPT_HDR_REVISION	0x00010000
	uint32_t	hdr_size;
	uint32_t	hdr_crc_self;
	uint32_t	__reserved;
	uint64_t	hdr_lba_self;
	uint64_t	hdr_lba_alt;
	uint64_t	hdr_lba_start;
	uint64_t	hdr_lba_end;
	struct uuid	hdr_uuid;
	uint64_t	hdr_lba_table;
	uint32_t	hdr_entries;
	uint32_t	hdr_entsz;
	uint32_t	hdr_crc_table;
	/*
	 * The header as defined in the EFI spec is not a multiple of 8 bytes
	 * and given that the alignment requirement is on an 8 byte boundary,
	 * padding will happen. We make the padding explicit so that we can
	 * correct the value returned by sizeof() when we put the size of the
	 * header in field hdr_size, or otherwise use offsetof().
	 */
	uint32_t	padding;
};

struct gpt_ent {
	struct uuid	ent_type;
	struct uuid	ent_uuid;
	uint64_t	ent_lba_start;
	uint64_t	ent_lba_end;
	uint64_t	ent_attr;
#define	GPT_ENT_ATTR_PLATFORM		(1ULL << 0)
#define	GPT_ENT_ATTR_BOOTME		(1ULL << 59)
#define	GPT_ENT_ATTR_BOOTONCE		(1ULL << 58)
#define	GPT_ENT_ATTR_BOOTFAILED		(1ULL << 57)
	uint16_t	ent_name[36];		/* UTF-16. */
};

#define	GPT_ENT_TYPE_UNUSED		\
	{0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}}
#define	GPT_ENT_TYPE_EFI		\
	{0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}}
#define	GPT_ENT_TYPE_MBR		\
	{0x024dee41,0x33e7,0x11d3,0x9d,0x69,{0x00,0x08,0xc7,0x81,0xf3,0x9f}}
#define	GPT_ENT_TYPE_FREEBSD		\
	{0x516e7cb4,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define	GPT_ENT_TYPE_FREEBSD_SWAP	\
	{0x516e7cb5,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define	GPT_ENT_TYPE_FREEBSD_UFS	\
	{0x516e7cb6,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define	GPT_ENT_TYPE_FREEBSD_VINUM	\
	{0x516e7cb8,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define	GPT_ENT_TYPE_FREEBSD_ZFS	\
	{0x516e7cba,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
#define	GPT_ENT_TYPE_FREEBSD_BOOT	\
	{0x83bd6b9d,0x7f41,0x11dc,0xbe,0x0b,{0x00,0x15,0x60,0xb8,0x4f,0x0f}}

/*
 * The following are unused but documented here to avoid reuse.
 *
 * GPT_ENT_TYPE_FREEBSD_UFS2	\
 *	{0x516e7cb7,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
 */

/*
 * Foreign partition types that we're likely to encounter. Note that Linux
 * apparently choose to share data partitions with MS. I don't what the
 * advantage might be. I can see how sharing swap partitions is advantageous
 * though.
 */
#define	GPT_ENT_TYPE_MS_RESERVED	\
	{0xe3c9e316,0x0b5c,0x4db8,0x81,0x7d,{0xf9,0x2d,0xf0,0x02,0x15,0xae}}
#define	GPT_ENT_TYPE_MS_BASIC_DATA	\
	{0xebd0a0a2,0xb9e5,0x4433,0x87,0xc0,{0x68,0xb6,0xb7,0x26,0x99,0xc7}}
#define	GPT_ENT_TYPE_MS_LDM_METADATA	\
	{0x5808c8aa,0x7e8f,0x42e0,0x85,0xd2,{0xe1,0xe9,0x04,0x34,0xcf,0xb3}}
#define	GPT_ENT_TYPE_MS_LDM_DATA	\
	{0xaf9b60a0,0x1431,0x4f62,0xbc,0x68,{0x33,0x11,0x71,0x4a,0x69,0xad}}

#define	GPT_ENT_TYPE_LINUX_DATA		GPT_ENT_TYPE_MS_BASIC_DATA
#define	GPT_ENT_TYPE_LINUX_RAID		\
	{0xa19d880f,0x05fc,0x4d3b,0xa0,0x06,{0x74,0x3f,0x0f,0x84,0x91,0x1e}}
#define	GPT_ENT_TYPE_LINUX_SWAP		\
	{0x0657fd6d,0xa4ab,0x43c4,0x84,0xe5,{0x09,0x33,0xc8,0x4b,0x4f,0x4f}}
#define	GPT_ENT_TYPE_LINUX_LVM		\
	{0xe6d6d379,0xf507,0x44c2,0xa2,0x3c,{0x23,0x8f,0x2a,0x3d,0xf9,0x28}}

#define	GPT_ENT_TYPE_APPLE_BOOT		\
	{0x426F6F74,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define	GPT_ENT_TYPE_APPLE_HFS		\
	{0x48465300,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define	GPT_ENT_TYPE_APPLE_UFS		\
	{0x55465300,0x0000,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define	GPT_ENT_TYPE_APPLE_ZFS		\
	{0x6a898cc3,0x1dd2,0x11b2,0x99,0xa6,{0x08,0x00,0x20,0x73,0x66,0x31}}
#define	GPT_ENT_TYPE_APPLE_RAID		\
	{0x52414944,0x0000,0x11aa,0xaa,0x22,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define	GPT_ENT_TYPE_APPLE_RAID_OFFLINE	\
	{0x52414944,0x5f4f,0x11aa,0xaa,0x22,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define GPT_ENT_TYPE_APPLE_LABEL	\
    	{0x4C616265,0x6c00,0x11aa,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}
#define	GPT_ENT_TYPE_APPLE_TV_RECOVERY	\
    	{0x5265636f,0x7665,0x11AA,0xaa,0x11,{0x00,0x30,0x65,0x43,0xec,0xac}}

#define	GPT_ENT_TYPE_NETBSD_FFS		\
	{0x49f48d5a,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define	GPT_ENT_TYPE_NETBSD_LFS		\
	{0x49f48d82,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define	GPT_ENT_TYPE_NETBSD_SWAP	\
	{0x49f48d32,0xb10e,0x11dc,0xB9,0x9B,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define	GPT_ENT_TYPE_NETBSD_RAID	\
	{0x49f48daa,0xb10e,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define	GPT_ENT_TYPE_NETBSD_CCD		\
	{0x2db519c4,0xb10f,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
#define	GPT_ENT_TYPE_NETBSD_CGD		\
	{0x2db519ec,0xb10f,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}

/*
 * Boot partition used by GRUB 2.
 */
#define	GPT_ENT_TYPE_BIOS_BOOT		\
	{0x21686148,0x6449,0x6e6f,0x74,0x4e,{0x65,0x65,0x64,0x45,0x46,0x49}}

#endif /* _SYS_GPT_H_ */


code:
/*-
 * Copyright (c) 2001 Tobias Weingartner
 * 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 ``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.
 *
 * $OpenBSD: hash.h,v 1.4 2004/05/25 18:37:23 jmc Exp $
 * $FreeBSD: release/9.0.0/sys/sys/hash.h 168557 2007-04-09 22:55:14Z thompsa $
 */

#ifndef _SYS_HASH_H_
#define	_SYS_HASH_H_
#include <sys/types.h>

/* Convenience */
#ifndef	HASHINIT
#define	HASHINIT	5381
#define	HASHSTEP(x,c)	(((x << 5) + x) + (c))
#endif

/*
 * Return a 32-bit hash of the given buffer.  The init
 * value should be 0, or the previous hash value to extend
 * the previous hash.
 */
static __inline uint32_t
hash32_buf(const void *buf, size_t len, uint32_t hash)
{
	const unsigned char *p = buf;

	while (len--)
		hash = HASHSTEP(hash, *p++);

	return hash;
}

/*
 * Return a 32-bit hash of the given string.
 */
static __inline uint32_t
hash32_str(const void *buf, uint32_t hash)
{
	const unsigned char *p = buf;

	while (*p)
		hash = HASHSTEP(hash, *p++);

	return hash;
}

/*
 * Return a 32-bit hash of the given string, limited by N.
 */
static __inline uint32_t
hash32_strn(const void *buf, size_t len, uint32_t hash)
{
	const unsigned char *p = buf;

	while (*p && len--)
		hash = HASHSTEP(hash, *p++);

	return hash;
}

/*
 * Return a 32-bit hash of the given string terminated by C,
 * (as well as 0).  This is mainly here as a helper for the
 * namei() hashing of path name parts.
 */
static __inline uint32_t
hash32_stre(const void *buf, int end, const char **ep, uint32_t hash)
{
	const unsigned char *p = buf;

	while (*p && (*p != end))
		hash = HASHSTEP(hash, *p++);

	if (ep)
		*ep = p;

	return hash;
}

/*
 * Return a 32-bit hash of the given string, limited by N,
 * and terminated by C (as well as 0).  This is mainly here
 * as a helper for the namei() hashing of path name parts.
 */
static __inline uint32_t
hash32_strne(const void *buf, size_t len, int end, const char **ep,
    uint32_t hash)
{
	const unsigned char *p = buf;

	while (*p && (*p != end) && len--)
		hash = HASHSTEP(hash, *p++);

	if (ep)
		*ep = p;

	return hash;
}
#endif /* !_SYS_HASH_H_ */


code:
/*-
 * Copyright (c) 2010 Lawrence Stewart <lstewart@freebsd.org>
 * Copyright (c) 2010 The FreeBSD Foundation
 * All rights reserved.
 *
 * This software was developed by Lawrence Stewart while studying at the Centre
 * for Advanced Internet Architectures, Swinburne University of Technology, made
 * possible in part by grants from the FreeBSD Foundation and Cisco University
 * Research Program Fund at Community Foundation Silicon Valley.
 *
 * Portions of this software were developed at the Centre for Advanced
 * Internet Architectures, Swinburne University of Technology, Melbourne,
 * Australia by Lawrence Stewart 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/sys/sys/hhook.h 220560 2011-04-12 08:13:18Z lstewart $
 */

/*
 * A KPI modelled on the pfil framework for instantiating helper hook points
 * within the kernel for use by Khelp modules. Originally released as part of
 * the NewTCP research project at Swinburne University of Technology's Centre
 * for Advanced Internet Architectures, Melbourne, Australia, which was made
 * possible in part by a grant from the Cisco University Research Program Fund
 * at Community Foundation Silicon Valley. More details are available at:
 *   http://caia.swin.edu.au/urp/newtcp/
 */

#ifndef _SYS_HHOOK_H_
#define _SYS_HHOOK_H_

/* XXXLAS: Is there a way around this? */
#include <sys/lock.h>
#include <sys/rmlock.h>

/* hhook_head flags. */
#define	HHH_ISINVNET		0x00000001 /* Is the hook point in a vnet? */

/* Flags common to  all register functions. */
#define	HHOOK_WAITOK		0x00000001 /* Sleeping allowed. */
#define	HHOOK_NOWAIT		0x00000002 /* Sleeping disallowed. */
/* Flags only relevant to hhook_head_register() and hhook_head_is_virtual(). */
#define	HHOOK_HEADISINVNET	0x00000100 /* Public proxy for HHH_ISINVNET. */

/* Helper hook types. */
#define	HHOOK_TYPE_TCP		1

struct helper;
struct osd;

/* Signature for helper hook functions. */
typedef int (*hhook_func_t)(int32_t hhook_type, int32_t hhook_id, void *udata,
    void *ctx_data, void *hdata, struct osd *hosd);

/*
 * Information required to add/remove a helper hook function to/from a helper
 * hook point.
 */
struct hookinfo {
	hhook_func_t	hook_func;
	struct helper	*hook_helper;
	void		*hook_udata;
	int32_t		hook_id;
	int32_t		hook_type;
};

/*
 * Ideally this would be private but we need access to the hhh_nhooks member
 * variable in order to make the HHOOKS_RUN_IF() macro low impact.
 */
struct hhook_head {
	STAILQ_HEAD(hhook_list, hhook)	hhh_hooks;
	struct rmlock			hhh_lock;
	int32_t				hhh_id;
	int32_t				hhh_nhooks;
	int32_t				hhh_type;
	uint32_t			hhh_flags;
	volatile uint32_t		hhh_refcount;
	LIST_ENTRY(hhook_head)		hhh_next;
};

/* Public KPI functions. */
void	hhook_run_hooks(struct hhook_head *hhh, void *ctx_data, struct osd *hosd);

int	hhook_add_hook(struct hhook_head *hhh, struct hookinfo *hki,
    uint32_t flags);

int	hhook_add_hook_lookup(struct hookinfo *hki, uint32_t flags);

int	hhook_remove_hook(struct hhook_head *hhh, struct hookinfo *hki);

int	hhook_remove_hook_lookup(struct hookinfo *hki);

int	hhook_head_register(int32_t hhook_type, int32_t hhook_id,
    struct hhook_head **hhh, uint32_t flags);

int	hhook_head_deregister(struct hhook_head *hhh);

int	hhook_head_deregister_lookup(int32_t hhook_type, int32_t hhook_id);

struct hhook_head * hhook_head_get(int32_t hhook_type, int32_t hhook_id);

void	hhook_head_release(struct hhook_head *hhh);

uint32_t hhook_head_is_virtualised(struct hhook_head *hhh);

uint32_t hhook_head_is_virtualised_lookup(int32_t hook_type, int32_t hook_id);

/*
 * A wrapper around hhook_run_hooks() that only calls the function if at least
 * one helper hook function is registered for the specified helper hook point.
 */
#define	HHOOKS_RUN_IF(hhh, ctx_data, hosd) do {				\
	if (hhh != NULL && hhh->hhh_nhooks > 0)				\
		hhook_run_hooks(hhh, ctx_data, hosd);			\
} while (0)

/*
 * WARNING: This macro should only be used in code paths that execute
 * infrequently, otherwise the refcounting overhead would be excessive.
 *
 * A similar wrapper to HHOOKS_RUN_IF() for situations where the caller prefers
 * not to lookup and store the appropriate hhook_head pointer themselves.
 */
#define	HHOOKS_RUN_LOOKUP_IF(hhook_type, hhook_id, ctx_data, hosd) do {	\
	struct hhook_head *_hhh;					\
									\
	_hhh = hhook_head_get(hhook_type, hhook_id);			\
	if (_hhh != NULL) {						\
		if (_hhh->hhh_nhooks > 0)				\
			hhook_run_hooks(_hhh, ctx_data, hosd);		\
		hhook_head_release(_hhh);				\
	}								\
} while (0)

#endif /* _SYS_HHOOK_H_ */


code:
/*-
 * Copyright (c) 2000-2001 Boris Popov
 * 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/sys/sys/iconv.h 206361 2010-04-07 16:50:38Z joel $
 */
#ifndef _SYS_ICONV_H_
#define _SYS_ICONV_H_

#define	ICONV_CSNMAXLEN		31	/* maximum length of charset name */
#define	ICONV_CNVNMAXLEN	31	/* maximum length of converter name */
/* maximum size of data associated with cs pair */
#define	ICONV_CSMAXDATALEN	(sizeof(caddr_t) * 0x200 + sizeof(uint32_t) * 0x200 * 0x80)

#define	XLAT16_ACCEPT_NULL_OUT		0x01000000
#define	XLAT16_ACCEPT_NULL_IN		0x02000000
#define	XLAT16_HAS_LOWER_CASE		0x04000000
#define	XLAT16_HAS_UPPER_CASE		0x08000000
#define	XLAT16_HAS_FROM_LOWER_CASE	0x10000000
#define	XLAT16_HAS_FROM_UPPER_CASE	0x20000000
#define	XLAT16_IS_3BYTE_CHR		0x40000000

#define	KICONV_LOWER		1	/* tolower converted character */
#define	KICONV_UPPER		2	/* toupper converted character */
#define	KICONV_FROM_LOWER	4	/* tolower source character, then convert */
#define	KICONV_FROM_UPPER	8	/* toupper source character, then convert */
#define	KICONV_WCTYPE		16	/* towlower/towupper characters */

#define	KICONV_WCTYPE_NAME	"_wctype"

/*
 * Entry for cslist sysctl
 */
#define	ICONV_CSPAIR_INFO_VER	1

struct iconv_cspair_info {
	int	cs_version;
	int	cs_id;
	int	cs_base;
	int	cs_refcount;
	char	cs_to[ICONV_CSNMAXLEN];
	char	cs_from[ICONV_CSNMAXLEN];
};

/*
 * Paramters for 'add' sysctl
 */
#define	ICONV_ADD_VER	1

struct iconv_add_in {
	int	ia_version;
	char	ia_converter[ICONV_CNVNMAXLEN];
	char	ia_to[ICONV_CSNMAXLEN];
	char	ia_from[ICONV_CSNMAXLEN];
	int	ia_datalen;
	const void *ia_data;
};

struct iconv_add_out {
	int	ia_csid;
};

#ifndef _KERNEL

__BEGIN_DECLS

#define	ENCODING_UNICODE	"UTF-16BE"
#define	KICONV_VENDOR_MICSFT	1	/* Microsoft Vendor Code for quirk */

int   kiconv_add_xlat_table(const char *, const char *, const u_char *);
int   kiconv_add_xlat16_cspair(const char *, const char *, int);
int   kiconv_add_xlat16_cspairs(const char *, const char *);
int   kiconv_add_xlat16_table(const char *, const char *, const void *, int);
int   kiconv_lookupconv(const char *drvname);
int   kiconv_lookupcs(const char *tocode, const char *fromcode);
const char *kiconv_quirkcs(const char *, int);

__END_DECLS

#else /* !_KERNEL */

#include <sys/kobj.h>
#include <sys/module.h>			/* can't avoid that */
#include <sys/queue.h>			/* can't avoid that */
#include <sys/sysctl.h>			/* can't avoid that */

struct iconv_cspair;
struct iconv_cspairdata;

/*
 * iconv converter class definition
 */
struct iconv_converter_class {
	KOBJ_CLASS_FIELDS;
	TAILQ_ENTRY(iconv_converter_class)	cc_link;
};

struct iconv_cspair {
	int		cp_id;		/* unique id of charset pair */
	int		cp_refcount;	/* number of references from other pairs */
	const char *	cp_from;
	const char *	cp_to;
	void *		cp_data;
	struct iconv_converter_class * cp_dcp;
	struct iconv_cspair *cp_base;
	TAILQ_ENTRY(iconv_cspair)	cp_link;
};

#define	KICONV_CONVERTER(name,size)			\
    static struct iconv_converter_class iconv_ ## name ## _class = { \
	"iconv_"#name, iconv_ ## name ## _methods, size, NULL \
    };							\
    static moduledata_t iconv_ ## name ## _mod = {	\
	"iconv_"#name, iconv_converter_handler,		\
	(void*)&iconv_ ## name ## _class		\
    };							\
    DECLARE_MODULE(iconv_ ## name, iconv_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);

#define	KICONV_CES(name,size)				\
    static DEFINE_CLASS(iconv_ces_ ## name, iconv_ces_ ## name ## _methods, (size)); \
    static moduledata_t iconv_ces_ ## name ## _mod = {	\
	"iconv_ces_"#name, iconv_cesmod_handler,	\
	(void*)&iconv_ces_ ## name ## _class		\
    };							\
    DECLARE_MODULE(iconv_ces_ ## name, iconv_ces_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);

#ifdef MALLOC_DECLARE
MALLOC_DECLARE(M_ICONV);
#endif

/*
 * Basic conversion functions
 */
int iconv_open(const char *to, const char *from, void **handle);
int iconv_close(void *handle);
int iconv_conv(void *handle, const char **inbuf,
	size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
int iconv_conv_case(void *handle, const char **inbuf,
	size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype);
int iconv_convchr(void *handle, const char **inbuf,
	size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
int iconv_convchr_case(void *handle, const char **inbuf,
	size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype);
char* iconv_convstr(void *handle, char *dst, const char *src);
void* iconv_convmem(void *handle, void *dst, const void *src, int size);
int iconv_vfs_refcount(const char *fsname);

int towlower(int c, void *handle);
int towupper(int c, void *handle);

/*
 * Bridge struct of iconv functions
 */
struct iconv_functions {
	int (*open)(const char *to, const char *from, void **handle);
	int (*close)(void *handle);
	int (*conv)(void *handle, const char **inbuf, size_t *inbytesleft,
		char **outbuf, size_t *outbytesleft);
	int (*conv_case)(void *handle, const char **inbuf, size_t *inbytesleft,
		char **outbuf, size_t *outbytesleft, int casetype);
	int (*convchr)(void *handle, const char **inbuf, size_t *inbytesleft,
		char **outbuf, size_t *outbytesleft);
	int (*convchr_case)(void *handle, const char **inbuf, size_t *inbytesleft,
		char **outbuf, size_t *outbytesleft, int casetype);
};

#define VFS_DECLARE_ICONV(fsname)					\
	static struct iconv_functions fsname ## _iconv_core = {		\
		iconv_open,						\
		iconv_close,						\
		iconv_conv,						\
		iconv_conv_case,					\
		iconv_convchr,						\
		iconv_convchr_case					\
	};								\
	extern struct iconv_functions *fsname ## _iconv;		\
	static int fsname ## _iconv_mod_handler(module_t mod,		\
		int type, void *d);					\
	static int							\
	fsname ## _iconv_mod_handler(module_t mod, int type, void *d)	\
	{								\
		int error = 0;						\
		switch(type) {						\
		case MOD_LOAD:						\
			fsname ## _iconv = & fsname ## _iconv_core;	\
			break;						\
		case MOD_UNLOAD:					\
			error = iconv_vfs_refcount(#fsname);		\
			if (error)					\
				return (EBUSY);				\
			fsname ## _iconv = NULL;			\
			break;						\
		default:						\
			error = EINVAL;					\
			break;						\
		}							\
		return (error);						\
	}								\
	static moduledata_t fsname ## _iconv_mod = {			\
		#fsname"_iconv",					\
		fsname ## _iconv_mod_handler,				\
		NULL							\
	};								\
	DECLARE_MODULE(fsname ## _iconv, fsname ## _iconv_mod,		\
		       SI_SUB_DRIVERS, SI_ORDER_ANY);			\
	MODULE_DEPEND(fsname ## _iconv, fsname, 1, 1, 1);		\
	MODULE_DEPEND(fsname ## _iconv, libiconv, 2, 2, 2);		\
	MODULE_VERSION(fsname ## _iconv, 1)

/*
 * Internal functions
 */
int iconv_lookupcp(char **cpp, const char *s);

int iconv_converter_initstub(struct iconv_converter_class *dp);
int iconv_converter_donestub(struct iconv_converter_class *dp);
int iconv_converter_tolowerstub(int c, void *handle);
int iconv_converter_handler(module_t mod, int type, void *data);

#ifdef ICONV_DEBUG
#define ICDEBUG(format, ...) printf("%s: "format, __func__ , __VA_ARGS__)
#else
#define ICDEBUG(format, ...)
#endif

#endif /* !_KERNEL */

#endif /* !_SYS_ICONV_H_ */