//------------------------------------------------------------------- // myfiles.c // // This module creates a pseudo-file named '/proc/myfiles' that // lets an application see the names of the files it has opened. // // NOTE: Developed and tested using Linux kernel version 2.4.26. // // programmer: ALLAN CRUSE // written on: 01 DEC 2004 //------------------------------------------------------------------- #include // for init_module() #include // for create_proc_info_entry() static char modname[] = "myfiles"; static int my_get_info( char *buf, char **start, off_t off, int count ) { struct task_struct *task = current; struct files_struct *files = task->files; unsigned long i, len = 0; // show title for output len += sprintf( buf+len, "\nList of files opened by " ); len += sprintf( buf+len, "\'%s\' ", task->comm ); len += sprintf( buf+len, "(pid=%d):\n\n", task->pid ); // show the names for the opened files for (i = 0; i < files->next_fd; i++) { struct file *file = files->fd[i]; struct dentry *dentry = file->f_dentry; len += sprintf( buf+len, "%3d ", i ); len += sprintf( buf+len, "%s\n", dentry->d_name ); } len += sprintf( buf+len, "\n" ); return len; } int init_module( void ) { create_proc_info_entry( modname, 0, NULL, my_get_info ); return 0; //SUCCESS } void cleanup_module( void ) { remove_proc_entry( modname, NULL ); } MODULE_LICENSE("GPL");