This source file includes following definitions.
- bioattach
- bioopen
- bioclose
- bioioctl
- bio_register
- bio_unregister
- bio_lookup
- bio_validate
- bio_delegate_ioctl
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 #include <sys/param.h>
30 #include <sys/device.h>
31 #include <sys/ioctl.h>
32 #include <sys/malloc.h>
33 #include <sys/queue.h>
34 #include <sys/systm.h>
35
36 #include <dev/biovar.h>
37
38 struct bio_mapping {
39 LIST_ENTRY(bio_mapping) bm_link;
40 struct device *bm_dev;
41 int (*bm_ioctl)(struct device *, u_long, caddr_t);
42 };
43
44 LIST_HEAD(, bio_mapping) bios = LIST_HEAD_INITIALIZER(bios);
45
46 void bioattach(int);
47 int bioclose(dev_t, int, int, struct proc *);
48 int bioioctl(dev_t, u_long, caddr_t, int, struct proc *);
49 int bioopen(dev_t, int, int, struct proc *);
50
51 int bio_delegate_ioctl(struct bio_mapping *, u_long, caddr_t);
52 struct bio_mapping *bio_lookup(char *);
53 int bio_validate(void *);
54
55 void
56 bioattach(int nunits)
57 {
58 }
59
60 int
61 bioopen(dev_t dev, int flags, int mode, struct proc *p)
62 {
63 return (0);
64 }
65
66 int
67 bioclose(dev_t dev, int flags, int mode, struct proc *p)
68 {
69 return (0);
70 }
71
72 int
73 bioioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
74 {
75 struct bio_locate *locate;
76 struct bio_common *common;
77 char name[16];
78 int error;
79
80 switch (cmd) {
81 case BIOCLOCATE:
82 locate = (struct bio_locate *)addr;
83 error = copyinstr(locate->bl_name, name, 16, NULL);
84 if (error != 0)
85 return (error);
86 locate->bl_cookie = bio_lookup(name);
87 if (locate->bl_cookie == NULL)
88 return (ENOENT);
89 break;
90
91 default:
92 common = (struct bio_common *)addr;
93 if (!bio_validate(common->bc_cookie))
94 return (ENOENT);
95 return (bio_delegate_ioctl(
96 (struct bio_mapping *)common->bc_cookie, cmd, addr));
97 }
98 return (0);
99 }
100
101 int
102 bio_register(struct device *dev, int (*ioctl)(struct device *, u_long, caddr_t))
103 {
104 struct bio_mapping *bm;
105
106 MALLOC(bm, struct bio_mapping *, sizeof *bm, M_DEVBUF, M_NOWAIT);
107 if (bm == NULL)
108 return (ENOMEM);
109 bm->bm_dev = dev;
110 bm->bm_ioctl = ioctl;
111 LIST_INSERT_HEAD(&bios, bm, bm_link);
112 return (0);
113 }
114
115 void
116 bio_unregister(struct device *dev)
117 {
118 struct bio_mapping *bm, *next;
119
120 for (bm = LIST_FIRST(&bios); bm != NULL; bm = next) {
121 next = LIST_NEXT(bm, bm_link);
122
123 if (dev == bm->bm_dev) {
124 LIST_REMOVE(bm, bm_link);
125 free(bm, M_DEVBUF);
126 }
127 }
128 }
129
130 struct bio_mapping *
131 bio_lookup(char *name)
132 {
133 struct bio_mapping *bm;
134
135 LIST_FOREACH(bm, &bios, bm_link)
136 if (strcmp(name, bm->bm_dev->dv_xname) == 0)
137 return (bm);
138 return (NULL);
139 }
140
141 int
142 bio_validate(void *cookie)
143 {
144 struct bio_mapping *bm;
145
146 LIST_FOREACH(bm, &bios, bm_link)
147 if (bm == cookie)
148 return (1);
149 return (0);
150 }
151
152 int
153 bio_delegate_ioctl(struct bio_mapping *bm, u_long cmd, caddr_t addr)
154 {
155 return (bm->bm_ioctl(bm->bm_dev, cmd, addr));
156 }