diff -urN cfree-1.1/Makefile cfree-2.0/Makefile --- cfree-1.1/Makefile 2003-06-10 12:24:08.000000000 -0400 +++ cfree-2.0/Makefile 2004-08-02 21:30:59.000000000 -0400 @@ -1,21 +1,23 @@ -TARGET := procfs WARN := -W -Wstrict-prototypes -Wmissing-prototypes -INCLUDE := -isystem /lib/modules/`uname -r`/build/include -CFLAGS := -c -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE} CC := gcc -cfree.o: cfree.c - $(CC) $(CFLAGS) -o cfree.o cfree.c +obj-m := cfree.o + +all: cfree_front cfree +.PHONY: all install + +cfree: + $(MAKE) -C /lib/modules/`uname -r`/build SUBDIRS=$(PWD) modules cfree_front: cfree_front.c $(CC) -DDEBUG -o cfree_front cfree_front.c -proctest2.o: proctest2.c - $(CC) $(CFLAGS) -o proctest2.o proctest2.c +install: cfree + $(MAKE) -C /lib/modules/`uname -r`/build SUBDIRS=$(PWD) modules_install ${TARGET}.o: ${TARGET}.c $(CC) $(CFLAGS) -o $(TARGET).o $(TARGET).c -tests: tests.c - $(CC) -g -o tests tests.c - +.PHONY: clean +clean: + rm -f *.o .*.o.cmd *.ko .*.ko.cmd cfree.mod.c cfree_front diff -urN cfree-1.1/cfree.c cfree-2.0/cfree.c --- cfree-1.1/cfree.c 2003-06-10 12:24:08.000000000 -0400 +++ cfree-2.0/cfree.c 2004-08-02 21:32:24.000000000 -0400 @@ -13,17 +13,26 @@ * * NOTE: this will not free locked pages. */ + +/* + * [August 2004 Mathieu Desnoyers] Port to 2.6 kernel + */ + #include #include #include +#include #include #include #include #include +#include #include -#define MODULE_VERSION "$Id: cfree.c,v 1.11 2003/06/10 19:30:31 adlr Exp $" -#define MODULE_NAME "cfree" +#define DRV_VERSION "2.0" +#define DRV_NAME "cfree" +#define DRV_RELDATE "02Aug2004" + #define PROC_FILENAME "cfree" #define CLEAR 0 /* clear the buffers */ #define VIEW 1 /* only view them */ @@ -34,6 +43,10 @@ #define QUIET 1 +static char version[] __initdata = +KERN_INFO DRV_NAME ".c:" DRV_VERSION " " DRV_RELDATE " adlr@umich.edu\n" +KERN_INFO " http://gizmolabs.org/~andrew/andrewweb/projects.php\n"; + static struct proc_dir_entry *d; static char data[LEN + 1]; static int pages; @@ -55,8 +68,9 @@ static int cfree_path_lookup(const char *path, unsigned flags, struct nameidata *nd) { int error = 0; - if (path_init(path, flags, nd)) - error = path_walk(path, nd); + + error = path_lookup(path, flags, nd); + return error; } @@ -94,7 +108,7 @@ printk(KERN_INFO); for (i = 0; i < offset; i++) printk(" "); - printk("%x (clean)\n", pg->index); + printk("%lx (clean)\n", pg->index); #endif /* QUIET */ ret++; } @@ -107,7 +121,7 @@ printk(KERN_INFO); for (i = 0; i < offset; i++) printk(" "); - printk("%x (dirty)\n", pg->index); + printk("%lx (dirty)\n", pg->index); #endif /* QUIET */ ret++; } @@ -120,7 +134,7 @@ printk(KERN_INFO); for (i = 0; i < offset; i++) printk(" "); - printk("%x (locked)\n", pg->index); + printk("%lx (locked)\n", pg->index); #endif /* QUIET */ ret++; } @@ -132,7 +146,7 @@ printk(" "); printk("[%s]\n", root->d_name.name); if (!strcmp(root->d_name.name, "insmod")) { - printk(KERN_INFO " (parent: [%s]; name: %x)\n", + printk(KERN_INFO " (parent: [%s]; name: %s)\n", root->d_parent->d_name.name, root->d_name.name); } #endif /* QUIET */ @@ -142,10 +156,13 @@ #endif /* QUIET */ /* free my pages */ /* write dirty pages to disk */ - fsync_buffers_list(&root->d_inode->i_dirty_data_buffers); - fsync_buffers_list(&root->d_inode->i_dirty_buffers); + filemap_fdatawrite(root->d_inode->i_mapping); + + /* MD : unnecessary check ? fdatawrite should be enough. */ + filemap_fdatawait(root->d_inode->i_mapping); + /* now for the piece de resistance */ - invalidate_inode_pages(root->d_inode); + invalidate_inode_pages(root->d_inode->i_mapping); } return ret; } @@ -169,7 +186,7 @@ "\techo -n v /path/to/directory > /proc/" PROC_FILENAME "\n" "To clear the buffer cache allocated below a directory:\n" "\techo -n c /path/to/directory > /proc/" PROC_FILENAME "\n"; - slen = snprintf(data, LEN, "%i", pages); + slen = snprintf(data, LEN, "%sNumber of pages : %i\n", message, pages); len = MIN(slen, count); if (len) memcpy(page + off, data, len); @@ -191,14 +208,11 @@ int action = CLEAR; int ret = count; - MOD_INC_USE_COUNT; - if (count < 3) return -EINVAL; /* because 'v /' would be the smallest command */ if (buffer[0] == 'v') action = VIEW; else if (buffer[0] != 'c') { /* illegal command */ - MOD_DEC_USE_COUNT; return -EINVAL; } if (buffer[1] != ' ') @@ -206,7 +220,6 @@ len = MIN(LEN, count-2); if (copy_from_user(data, buffer+2, len)) { memcpy(data, "err\n", 5); - MOD_DEC_USE_COUNT; return -EFAULT; } data[len] = '\0'; @@ -214,7 +227,7 @@ printk(KERN_INFO "Got path: [%s]\n", data); #endif /* QUIET */ /* parse path */ - err = cfree_path_lookup(data, 1, &nd); + err = cfree_path_lookup(data, 0, &nd); if (err) { #ifdef QUIET printk(KERN_INFO "got error %i\n", err); @@ -229,12 +242,10 @@ /* free buffer cache from that dentry and below. */ pages = recursive_free(nd.dentry, 0, action); } else { - MOD_DEC_USE_COUNT; ret = -EINVAL; } path_release(&nd); end: - MOD_DEC_USE_COUNT; return ret; } @@ -247,14 +258,13 @@ d->read_proc = read_fxn; d->write_proc = write_fxn; d->owner = THIS_MODULE; - printk(KERN_INFO "%s %s initialized\n", MODULE_NAME, MODULE_VERSION); + printk(version); return 0; } /* free the module */ static void __exit cfree_cleanup(void) { remove_proc_entry(PROC_FILENAME, NULL); - printk(KERN_INFO "%s %s removed\n", MODULE_NAME, MODULE_VERSION); } module_init(cfree_init); @@ -266,5 +276,3 @@ * procfs */ MODULE_DESCRIPTION("Buffer-cache eraser"); MODULE_LICENSE("GPL"); - -EXPORT_NO_SYMBOLS;