Home | History | Annotate | Line # | Download | only in zbsdmod
compat_linux.h revision 1.5
      1 /*	$NetBSD: compat_linux.h,v 1.5 2010/12/26 09:02:52 nonaka Exp $	*/
      2 /*	$OpenBSD: compat_linux.h,v 1.5 2006/01/15 17:58:27 deraadt Exp $	*/
      3 
      4 /*
      5  * Copyright (c) 2005 Uwe Stuehler <uwe (at) bsdx.de>
      6  *
      7  * Permission to use, copy, modify, and distribute this software for any
      8  * purpose with or without fee is hereby granted, provided that the above
      9  * copyright notice and this permission notice appear in all copies.
     10  *
     11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  */
     19 
     20 /*
     21  * Declare the things that we need from the Linux headers.
     22  */
     23 
     24 #define	IS_ERR(ptr)	((unsigned long)(ptr) > (unsigned long)-1000L)
     25 
     26 #define MKDEV(ma,mi)	((ma)<<8 | (mi))
     27 
     28 #define S_IFBLK		0060000
     29 #define S_IFCHR		0020000
     30 
     31 struct file;
     32 struct inode;
     33 
     34 #include <sys/cdefs.h>
     35 #define	ELFSIZE	32
     36 #include <sys/exec_elf.h>
     37 #include <sys/types.h>
     38 #include <sys/errno.h>
     39 
     40 typedef long loff_t;
     41 
     42 struct file_operations {
     43 	struct module *owner;
     44 	void (*llseek) (void);
     45 	ssize_t (*read) (struct file *, char *, size_t, loff_t *);
     46 	ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
     47 	void (*readdir) (void);
     48 	void (*poll) (void);
     49 	void (*ioctl) (void);
     50 	void (*mmap) (void);
     51 	int (*open) (struct inode *, struct file *);
     52 	void (*flush) (void);
     53 	int (*release) (struct inode *, struct file *);
     54 	void (*fsync) (void);
     55 	void (*fasync) (void);
     56 	void (*lock) (void);
     57 	void (*readv) (void);
     58 	void (*writev) (void);
     59 	void (*sendpage) (void);
     60 	void (*get_unmapped_area)(void);
     61 #ifdef MAGIC_ROM_PTR
     62 	void (*romptr) (void);
     63 #endif /* MAGIC_ROM_PTR */
     64 };
     65 
     66 extern	struct file *open_exec(const char *);
     67 extern	int kernel_read(struct file *, unsigned long, char *, unsigned long);
     68 extern	int memcmp(const void *, const void *, size_t);
     69 extern	int register_chrdev(unsigned int, const char *, struct file_operations *);
     70 extern	int unregister_chrdev(unsigned int, const char *);
     71 extern	void printk(const char *, ...) __printflike(1, 2);
     72 extern	void *memcpy(void *, const void *, size_t);
     73 
     74 /* Linux LKM support */
     75 static const char __module_kernel_version[] __attribute__((section(".modinfo"))) =
     76 "kernel_version=" UTS_RELEASE;
     77 static const char __module_using_checksums[] __attribute__((section(".modinfo"))) =
     78 "using_checksums=1";
     79 
     80 /* procfs support */
     81 struct proc_dir_entry {
     82         unsigned short low_ino;
     83         unsigned short namelen;
     84         const char *name;
     85         unsigned short mode;
     86         unsigned short nlink;
     87         unsigned short uid;
     88         unsigned short gid;
     89         unsigned long size;
     90         void *proc_iops; /* inode operations */
     91         struct file_operations * proc_fops;
     92         void *get_info;
     93         struct module *owner;
     94         struct proc_dir_entry *next, *parent, *subdir;
     95         void *data;
     96         void *read_proc;
     97         void *write_proc;
     98         volatile int count;
     99         int deleted;
    100         unsigned short rdev;
    101 };
    102 extern	struct proc_dir_entry proc_root;
    103 extern	struct proc_dir_entry *proc_mknod(const char*, unsigned short,
    104     struct proc_dir_entry*, unsigned short);
    105 extern	void remove_proc_entry(const char *, struct proc_dir_entry *);
    106