Пример #1
0
/**
 * Init module method
 */
static int __init translate_init(void)
{
	printk(KERN_INFO "INIT: Translate Module wird hinzugefuegt\n");
	int i;
	// Try and get region for drivers
	int err =  alloc_chrdev_region(&trans_device, 0, 1, DEVICE_NAME);

	if (err != 0) {
	  printk(KERN_ALERT "INIT: Erstellen des devices ist fehlgeschlagen mit Error: %d\n", major);
	  return -1;
	}
	// Get major id of our device
	major = MAJOR(trans_device);

	// Allocate memory for our devices
	trans_devices = kmalloc(2 * sizeof(struct trans_dev), GFP_KERNEL);
	if (!trans_devices) {
		// If we couldn't alloc memory in kernel -> exit
		translate_exit();
		return -ENOMEM;
	}
	// Set the allocated memory for our devices
	memset(trans_devices, 0, 2 * sizeof(struct trans_dev));

	// setup each device
	for (i = 0; i < 2; i++) {
		setup_cdev(&trans_devices[i], i);
	}
	return 0;
}
Пример #2
0
static int __init ioctl_init(void)
{
//	int result;
    dev_t dev;

    /* Dynamically get major and minor device numbers */
    //result = alloc_chrdev_region(&dev, minor, nr_devs, "ioctl");
    //major = MAJOR(dev);

    /* if(result < 0){
     * 	printk(KERN_WARNING "ioctl: can't get major %d\n", major);
     * 	return result;
     * }
     * else{ */
    setup_cdev(&dev);
//	}



    return 0;
}