All pastes #17933 Raw Edit

Stuff

public c v1 · immutable
#17933 ·published 2005-07-17 20:33 UTC
rendered paste body
#include <linux/kernel.h>#include <linux/module.h>#include <linux/fs.h>#include <asm/uaccess.h>#include <linux/console_struct.h>	#include <linux/init.h>#include <linux/tty.h>#include <linux/kd.h>#include <linux/config.h>#define SUCCESS 0#define DEVICE_NAME "chardev"		#define BLINK_DELAY   HZ/5#define ALL_LEDS_ON   0x07#define RESTORE_LEDS  0xFFint init_module(void);void cleanup_module(void);static int device_open(struct inode *, struct file *);static int device_release(struct inode *, struct file *);struct tty_driver *my_driver;char kbledstatus = 0;static int Major;		static struct file_operations fops = {	.read = NULL,	.write = NULL,	.open = device_open,	.release = device_release};int init_module(void){int i;        Major = register_chrdev(0, DEVICE_NAME, &fops);	if (Major < 0) {	  printk(KERN_ALERT "Registering char device failed with %d\n", Major);	  return Major;	}	printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major);	printk(KERN_INFO "the driver, create a dev file with\n");	printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);	printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n");	printk(KERN_INFO "the device file.\n");	printk(KERN_INFO "Remove the device file and module when done.\n");	for (i = 0; i < MAX_NR_CONSOLES; i++) {		if (!vc_cons[i].d)			break;		printk(KERN_INFO "poet_atkm: console[%i/%i] #%i, tty %lx\n", i,		       MAX_NR_CONSOLES, vc_cons[i].d->vc_num,		       (unsigned long)vc_cons[i].d->vc_tty);	}	printk(KERN_INFO "kbleds: finished scanning consoles\n");	my_driver = vc_cons[fg_console].d->vc_tty->driver;	printk(KERN_INFO "kbleds: tty driver magic %x\n", my_driver->magic);	return SUCCESS;}void cleanup_module(void){	int ret = unregister_chrdev(Major, DEVICE_NAME);	if (ret < 0)		printk(KERN_ALERT "Error in unregister_chrdev: %d\n", ret);	(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,			    RESTORE_LEDS);}static int device_open(struct inode *inode, struct file *file){	(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,			    ALL_LEDS_ON);	return SUCCESS;}static int device_release(struct inode *inode, struct file *file){	(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,			    RESTORE_LEDS);	return 0;}static ssize_tdevice_write(struct file *filp, const char *buff, size_t len, loff_t * off){	printk(KERN_ALERT "Sorry, this operation isn't supported.\n");	return -EINVAL;}