15 #include <linux/module.h>
17 #include <linux/capability.h>
18 #include <linux/uio.h>
20 #include <linux/device.h>
26 #include <asm/uaccess.h>
33 static struct class *raw_class;
55 const int minor = iminor(inode);
60 filp->
f_op = &raw_ctl_fops;
69 bdev = raw_devices[minor].
binding;
82 if (++raw_devices[minor].inuse == 1)
83 filp->
f_path.dentry->d_inode->i_mapping =
100 static int raw_release(
struct inode *inode,
struct file *filp)
102 const int minor= iminor(inode);
106 bdev = raw_devices[minor].
binding;
107 if (--raw_devices[minor].inuse == 0) {
122 raw_ioctl(
struct file *filp,
unsigned int command,
unsigned long arg)
128 static int bind_set(
int number,
u64 major,
u64 minor)
134 if (number <= 0 || number >= max_raw_minors)
137 if (
MAJOR(dev) != major ||
MINOR(dev) != minor)
140 rawdev = &raw_devices[number];
156 if (
MAJOR(dev) == 0 && dev != 0)
188 static int bind_get(
int number,
dev_t *dev)
196 rawdev = &raw_devices[number];
200 *dev = bdev ? bdev->
bd_dev : 0;
209 static long raw_ctl_ioctl(
struct file *filp,
unsigned int command,
221 return bind_set(
rq.raw_minor,
rq.block_major,
rq.block_minor);
227 err = bind_get(
rq.raw_minor, &dev);
244 struct raw32_config_request {
250 static long raw_ctl_compat_ioctl(
struct file *
file,
unsigned int cmd,
253 struct raw32_config_request
__user *user_req = compat_ptr(arg);
254 struct raw32_config_request
rq;
263 return bind_set(
rq.raw_minor,
rq.block_major,
rq.block_minor);
269 err = bind_get(
rq.raw_minor, &dev);
293 .release = raw_release,
294 .unlocked_ioctl = raw_ioctl,
300 .unlocked_ioctl = raw_ctl_ioctl,
302 .compat_ioctl = raw_ctl_compat_ioctl,
309 static struct cdev raw_cdev;
316 static int __init raw_init(
void)
321 if (max_raw_minors < 1 || max_raw_minors > 65536) {
339 ret =
cdev_add(&raw_cdev, dev, max_raw_minors);
345 if (IS_ERR(raw_class)) {
348 ret = PTR_ERR(raw_class);
351 raw_class->
devnode = raw_devnode;
363 static void __exit raw_exit(
void)