1 /*        $NetBSD: compat_linux.h,v 1.7 2019/10/28 15:26:09 tsutsui 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@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 typedef long loff_t;
35 
36 struct file_operations {
37           struct module *owner;
38           void (*llseek) (void);
39           ssize_t (*read) (struct file *, char *, size_t, loff_t *);
40           ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
41           void (*readdir) (void);
42           void (*poll) (void);
43           void (*ioctl) (void);
44           void (*mmap) (void);
45           int (*open) (struct inode *, struct file *);
46           void (*flush) (void);
47           int (*release) (struct inode *, struct file *);
48           void (*fsync) (void);
49           void (*fasync) (void);
50           void (*lock) (void);
51           void (*readv) (void);
52           void (*writev) (void);
53           void (*sendpage) (void);
54           void (*get_unmapped_area)(void);
55 #ifdef MAGIC_ROM_PTR
56           void (*romptr) (void);
57 #endif /* MAGIC_ROM_PTR */
58 };
59 
60 extern    struct file *open_exec(const char *);
61 extern    int kernel_read(struct file *, unsigned long, char *, unsigned long);
62 extern    int memcmp(const void *, const void *, size_t);
63 extern    int register_chrdev(unsigned int, const char *, struct file_operations *);
64 extern    int unregister_chrdev(unsigned int, const char *);
65 extern    void printk(const char *, ...) __printflike(1, 2);
66 extern    void *memcpy(void *, const void *, size_t);
67 extern    void *memset(void *, int, size_t);
68 
69 /* procfs support */
70 struct proc_dir_entry {
71         unsigned short low_ino;
72         unsigned short namelen;
73         const char *name;
74         unsigned short mode;
75         unsigned short nlink;
76         unsigned short uid;
77         unsigned short gid;
78         unsigned long size;
79         void *proc_iops; /* inode operations */
80         struct file_operations * proc_fops;
81         void *get_info;
82         struct module *owner;
83         struct proc_dir_entry *next, *parent, *subdir;
84         void *data;
85         void *read_proc;
86         void *write_proc;
87         volatile int count;
88         int deleted;
89         unsigned short rdev;
90 };
91 extern    struct proc_dir_entry proc_root;
92 extern    struct proc_dir_entry *proc_mknod(const char*, unsigned short,
93     struct proc_dir_entry*, unsigned short);
94 extern    void remove_proc_entry(const char *, struct proc_dir_entry *);
95