-
Notifications
You must be signed in to change notification settings - Fork 1
/
scull.h
90 lines (74 loc) · 2.8 KB
/
scull.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <linux/cdev.h>
#include <linux/module.h>
#include <linux/ioctl.h>
#include <linux/wait.h>
/* DEBUG */
#undef DEBUG_ON
#ifdef DEBUG_MODE
/* Enable debug messages */
#ifdef __KERNEL__
#define DEBUG_ON(fmt, args...) printk(KERN_DEBUG "scull: " fmt, ## args)
#else
#define DEBUG_ON(fmt, args...) fprintf(stderr, fmt, ## args)
#endif
#else
#define DEBUG_ON(fmt, args...) /*No debug if DEBUG_MODE is not defined*/
#endif
#undef DEBUG_OFF
#define DEBUG_OFF(fmt,args...) /* Disable debug */
/* defines the major number of the devices, if 0 the major is dinamically allocated */
#define SCULL_MAJOR 0
/* first minor to be allocated on the device */
#define SCULL_MINOR 0
#define SCULL_NR_DEVS 4
#define SCULL_BUFFER 2048
extern unsigned int scull_major;
extern unsigned int scull_minor;
extern unsigned int scull_nr_devs; /* number of devices */
extern unsigned int scull_quantum;
extern unsigned int scull_qset;
extern struct scull_pipe *scull_devices;
/* device number */
/*dev_t dev;*/
/* function prototypes of device setup */
/*int create_dev(void);*/
/* function and variables prototypes of file operations */
extern struct file_operations scull_fops;
/*int scull_open(struct inode *inode, struct file *filp);*/
extern int create_dev(void);
/* this structure identifies each device into the driver */
struct scull_pipe {
wait_queue_head_t inq, outq; /* read and write queues */
char *buffer, *end; /* begin of buf, end of buf */
int buffersize; /* used in pointer arithmetic */
char *rp, *wp; /* where to read, where to write */
int nreaders, nwriters; /* number of opening for r/w */
struct fasync_struct *async_queue; /*asynchronous readers */
struct semaphore sem; /* mutual exclusion semaphore */
struct cdev cdev; /* Char device structure */
};
/* IOCTLs */
/*sets the scull magic number*/
#define SCULL_IOC_MAGIC 0xF7
#define SCULL_IOCRESET _IO(SCULL_IOC_MAGIC, 0)
/*
* S means 'Set' through a ptr
* T means "Tell" directly with the argument value
* G means "GET": reply by setting through a pointer
* Q means "Query": response is on the return value
* X means "eXchange": switch G and S atomically
* H means "sHift": switch T and Q atomically
*/
#define SCULL_IOCSQUANTUM _IOW(SCULL_IOC_MAGIC, 1, int)
#define SCULL_IOCSQSET _IOW(SCULL_IOC_MAGIC, 2, int)
#define SCULL_IOCTQUANTUM _IO(SCULL_IOC_MAGIC, 3)
#define SCULL_IOCTQSET _IO(SCULL_IOC_MAGIC, 4)
#define SCULL_IOCGQUANTUM _IOR(SCULL_IOC_MAGIC, 5, int)
#define SCULL_IOCGQSET _IOR(SCULL_IOC_MAGIC, 6, int)
#define SCULL_IOCQQUANTUM _IO(SCULL_IOC_MAGIC, 7)
#define SCULL_IOCQQSET _IO(SCULL_IOC_MAGIC, 8)
#define SCULL_IOCXQUANTUM _IOWR(SCULL_IOC_MAGIC, 9, int)
#define SCULL_IOCXQSET _IOWR(SCULL_IOC_MAGIC, 10, int)
#define SCULL_IOCHQUANTUM _IO(SCULL_IOC_MAGIC, 11)
#define SCLL_IOcHQSET _IO(SCULL_IOC_MAGIC, 12)
#define SCULL_IOC_MAXNR 14