//------------------------------------------------------------------- // updown.c // // This module's 'get_info()' function shows how to acquire and // release the kernel's 'ide_cfg_sem' semaphore on workstations // in the USF Kudlick Classroom and Fifth-Floor of Harney labs. // The kernel-address of this semaphore is hard-coded here, and // was derived from information in the (uncompressed) 'vmlinux' // kernel binary using this command-sequence: // // $ cd /usr/src/linux // $ objdump -t vmlinux | grep ide_cfg_sem // // NOTE: Developed and tested with Linux kernel version 2.6.10. // // programmer: ALLAN CRUSE // written on: 14 MAR 2005 //------------------------------------------------------------------- #include // for init_module() #include // for create_proc_info_entry() char modname[] = "updown"; struct semaphore *semp = (struct semaphore *)0xC02BBDC0; // USF only! int my_get_info( char *buf, char **start, off_t off, int count ) { int len = 0; len += sprintf( buf+len, "ide_cfg_sem.count=%d\n", semp->count.counter ); down_interruptible( semp ); // <--- acquire the semaphore len += sprintf( buf+len, "ide_cfg_sem.count=%d\n", semp->count.counter ); up( semp ); // <--- release the semaphore len += sprintf( buf+len, "ide_cfg_sem.count=%d\n", semp->count.counter ); 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");