glendix
changeset 83:6fdffc287daf slashnet
Tutorial: How to process the written instructions in netfs
| author | Rahul Murmuria <rahul@murmuria.in> |
|---|---|
| date | Sat Apr 04 21:17:51 2009 -0500 (2009-04-04) |
| parents | 5fe1f801a6c6 |
| children | 9d1ec2b3b2ac |
| files | netfs/cs.c netfs/ether.c netfs/net.c netfs/net.h netfs/tcp.c |
line diff
1.1 --- a/netfs/cs.c Sat Apr 04 19:25:43 2009 -0500 1.2 +++ b/netfs/cs.c Sat Apr 04 21:17:51 2009 -0500 1.3 @@ -16,7 +16,6 @@ 1.4 cs_tmp = kmalloc(TMPSIZE, GFP_KERNEL); 1.5 memset (cs_tmp, 0, TMPSIZE); 1.6 slashnet_create_file(sb, root, "cs", cs_tmp); 1.7 - //kfree(cs_tmp); 1.8 /* 1.9 * NOTE: cs_tmp should not be free'd here because the same memory 1.10 * is being assigned to inode->-_private in the main program. 1.11 @@ -26,5 +25,15 @@ 1.12 1.13 } 1.14 1.15 +/* 1.16 + * Processing the written instructions 1.17 + */ 1.18 1.19 +void slashnet_cs_process (struct file *filp) 1.20 +{ 1.21 + char *tmp; 1.22 + tmp = (char *)(filp->private_data); 1.23 + strcat(tmp, ":processed"); 1.24 +} 1.25 1.26 +
2.1 --- a/netfs/ether.c Sat Apr 04 19:25:43 2009 -0500 2.2 +++ b/netfs/ether.c Sat Apr 04 21:17:51 2009 -0500 2.3 @@ -17,7 +17,6 @@ 2.4 memset (ether_tmp, 0, TMPSIZE); 2.5 /* if ether0 exists */ 2.6 slashnet_create_dir(sb, root, "ether0"); 2.7 - kfree(ether_tmp); 2.8 } 2.9 2.10
3.1 --- a/netfs/net.c Sat Apr 04 19:25:43 2009 -0500 3.2 +++ b/netfs/net.c Sat Apr 04 21:17:51 2009 -0500 3.3 @@ -66,14 +66,6 @@ 3.4 if (retval) 3.5 return -EFAULT; 3.6 3.7 - /* debug */ 3.8 - /* 3.9 - printk("*** value buffer has in read_file: %s ***\n", buffer); 3.10 - printk("*** value of retval in copy_to_user: %d ***\n", retval); 3.11 - printk("*** value of offset in read_file: %d ***\n", (int) *offset); 3.12 - printk("*** value of count in read_file: %d ***\n", count); 3.13 - printk("*** value of len in read_file: %d ***\n", len); 3.14 - */ 3.15 *offset += count; 3.16 return count; 3.17 } 3.18 @@ -94,8 +86,17 @@ 3.19 if(copy_from_user(tmp, dnsquery, count)) 3.20 return -EFAULT; 3.21 tmp[count-1] = '\0'; 3.22 + 3.23 + if (!strcmp(filp->f_dentry->d_name.name, "clone") && 3.24 + !strcmp(filp->f_dentry->d_parent->d_name.name, "tcp")) 3.25 + tcp_clone_process(filp); 3.26 + else if (!strcmp(filp->f_dentry->d_name.name, "cs") && 3.27 + !strcmp(filp->f_dentry->d_parent->d_name.name, "/")) 3.28 + slashnet_cs_process(filp); 3.29 + 3.30 /* debug */ 3.31 - printk("*** value buffer has in write_file: %s ***\n", (char *) filp->private_data); 3.32 + printk("*** %s/%s: %s ***\n", filp->f_dentry->d_parent->d_name.name, 3.33 + filp->f_dentry->d_name.name, (char *) filp->private_data); 3.34 3.35 return count; 3.36 } 3.37 @@ -110,7 +111,6 @@ 3.38 .write = slashnet_write_file, 3.39 }; 3.40 3.41 - 3.42 /* 3.43 * Create a file. 3.44 */ 3.45 @@ -137,8 +137,6 @@ 3.46 goto out_dput; 3.47 inode->i_fop = &slashnet_file_ops; 3.48 inode->i_private = initval; 3.49 - /* debug */ 3.50 - //printk("*** %s: initial val is %s ***\n", name, initval); 3.51 3.52 /* 3.53 * Put it all into the dentry cache and we're done.
4.1 --- a/netfs/net.h Sat Apr 04 19:25:43 2009 -0500 4.2 +++ b/netfs/net.h Sat Apr 04 21:17:51 2009 -0500 4.3 @@ -35,3 +35,9 @@ 4.4 void tcp_create_files (struct super_block *, struct dentry *); 4.5 void ether_create_files (struct super_block *, struct dentry *); 4.6 4.7 +/* 4.8 + * File processing of instructions written to individual file 4.9 + */ 4.10 +void slashnet_cs_process (struct file *); 4.11 +void tcp_clone_process (struct file *); 4.12 +
5.1 --- a/netfs/tcp.c Sat Apr 04 19:25:43 2009 -0500 5.2 +++ b/netfs/tcp.c Sat Apr 04 21:17:51 2009 -0500 5.3 @@ -20,12 +20,10 @@ 5.4 clone_tmp = kmalloc(TMPSIZE, GFP_KERNEL); 5.5 memset (clone_tmp, 0, TMPSIZE); 5.6 slashnet_create_file(sb, subdir, "clone", clone_tmp); 5.7 - //kfree(clone_tmp); 5.8 5.9 stats_tmp = kmalloc(TMPSIZE, GFP_KERNEL); 5.10 memset (stats_tmp, 0, TMPSIZE); 5.11 slashnet_create_file(sb, subdir, "stats", stats_tmp); 5.12 - //kfree(stats_tmp); 5.13 /* 5.14 * NOTE: stat_tmp and clone_tmp should not be free'd here because 5.15 * the same memory is being assigned to inode->-_private in the 5.16 @@ -36,5 +34,18 @@ 5.17 } 5.18 } 5.19 5.20 +/* 5.21 + * Processing the written instructions 5.22 + */ 5.23 5.24 +/* 5.25 + * /net/tcp/clone 5.26 + */ 5.27 5.28 +void tcp_clone_process (struct file *filp) 5.29 +{ 5.30 + char *tmp; 5.31 + tmp = (char *)(filp->private_data); 5.32 + strcat(tmp, ":processed"); 5.33 +} 5.34 +
