//------------------------------------------------------------------- // ide_lock.c // // This module's 'get_info()' function shows how to lock and // unlock the global 'ide_lock' kernel variable, in order to // synchronize accesses to the IDE Hard Disk Controller [see // Linux Device Drivers (3rd Edition), Chapter 5]. // // NOTE: Written and tested with Linux kernel version 2.6.10 // // programmer: ALLAN CRUSE // written on: 12 MAR 2005 //------------------------------------------------------------------- #include // for init_module() #include // for create_proc_info_entry() extern spinlock_t ide_lock; // global variable in the kernel char modname[] = "ide_lock"; // used to create '/proc' entry int my_get_info( char *buf, char **start, off_t off, int count ) { int len; len = 0; len += sprintf( buf+len, "ide_lock=%lu\n", ide_lock.lock ); spin_lock( &ide_lock ); len += sprintf( buf+len, "ide_lock=%lu\n", ide_lock.lock ); spin_unlock( &ide_lock ); len += sprintf( buf+len, "ide_lock=%lu\n", ide_lock.lock ); return len; } int init_module( void ) { printk( "<1>\nInstalling \'%s\' module\n", modname ); create_proc_info_entry( modname, 0, NULL, my_get_info ); return 0; //SUCCESS } void cleanup_module( void ) { remove_proc_entry( modname, NULL ); printk( "<1>Removing \'%s\' module\n", modname ); } MODULE_LICENSE("GPL");