#include <linux/module.h>
#include <linux/moduleparam.h>
+#include <linux/types.h>
#include <linux/kernel.h> /* printk(), min() */
#include <linux/slab.h> /* kmalloc() */
#include <linux/fs.h> /* everything... */
#include <linux/fcntl.h>
#include <linux/poll.h>
#include <linux/cdev.h>
+#include <linux/device.h>
#include <linux/sched.h>
#include <asm/uaccess.h>
static struct vdpram_dev *vdpram_devices;
static struct buffer_t *buffer;
static struct queue_t *queue;
+static struct class *vdpram_class;
static int vdpram_fasync(int fd, struct file *filp, int mode);
static int spacefree(struct vdpram_dev *dev);
printk(KERN_NOTICE "Error %d adding device%d\n", err, index);
}
-
+static char *vdpram_devnode(struct device *dev, umode_t *mode)
+{
+ return kasprintf(GFP_KERNEL, "%s", dev_name(dev));
+}
/* Initialize the devs; return how many we did */
int vdpram_init(void)
goto err_alloc;
}
+ vdpram_class = class_create(THIS_MODULE, "vdpram");
+ if (IS_ERR(vdpram_class)) {
+ result = PTR_ERR(vdpram_class);
+ goto err_alloc;
+ }
+ vdpram_class->devnode = vdpram_devnode;
+
memset(vdpram_devices, 0, vdpram_nr_devs * sizeof(struct vdpram_dev));
for (i = 0; i < vdpram_nr_devs; i++) {
if (i% 2 ==1) {
//printk("%s buffer[%x].begin =%x\n", __FUNCTION__, i, buffer[i].begin );
//printk("%s buffer[%x].buffersize =%x\n", __FUNCTION__, i, buffer[i].buffersize );
//printk("%s buffer[%x].end =%x\n", __FUNCTION__, i, buffer[i].end );
- }
+ }
+
+ for (i = 0; i < vdpram_nr_devs; i++)
+ device_create(vdpram_class, NULL, MKDEV(vdpram_major, i), NULL,
+ kasprintf(GFP_KERNEL, "vdpram%d", i));
return 0;
return; /* nothing else to release */
for (i = 0; i < vdpram_nr_devs; i++) {
+ device_destroy(vdpram_class, MKDEV(vdpram_major, i));
cdev_del(&vdpram_devices[i].cdev);
}
+ class_destroy(vdpram_class);
kfree(vdpram_devices);
for (i= 0;i < vdpram_nr_devs ; i++) {