Hello Everyone:<br> The first time to study fs ,and write a simple module to traverse the double list with super_block.<br>and the output of module is different with the result from the command cat /proc/filesystems.<br>
the output fs of module is 23,and the output fs of cat /proc/filesystems is 26. why?<br> <br> My Environments:<br>
# uname -r<br>
2.6.39.1<br>
# lsb_release -a<br>
No LSB modules are available.<br>Distributor ID: Ubuntu<br>Description: Ubuntu 11.04<br>Release: 11.04<br>Codename: natty<br>
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)<br clear="all"><br>my code is as followed:<br><br>#include<linux/module.h><br>#include<linux/init.h><br>#include<linux/sched.h><br>#include <linux/fs.h><br>
#include <linux/list.h><br>#include <linux/spinlock.h><br><br>#define addr_super_blocks 0xc173d0a0 <br>#define addr_sb_lock 0xc18f3ba0<br><br>#ifndef offsetof <br>#define offsetof(type, field) ((long) &((type *)0)->field) <br>
#endif /* offsetof */ <br> <br>#ifndef container_of <br>#define container_of(ptr, type, member) ({ \<br> const typeof( ((type *)0)->member ) *__mptr = (ptr); \<br> (type *)( (char *)__mptr - offsetof(type,member) );})<br>
#endif <br><br><br>static __init int sbinfo_init(void)<br>{<br> struct list_head *p;<br> int count = 0;<br> struct super_block *sb;<br><br> spin_lock((spinlock_t *)addr_sb_lock);<br> p = (struct list_head *)addr_super_blocks;<br>
p = p->next;<br> for (;p != (struct list_head *)addr_super_blocks;p = p->next) {<br> sb = container_of(p,struct super_block,s_list);<br> printk("<0>filesystem name:%s\n",sb->s_type->name);<br>
count++;<br> } <br> spin_unlock((spinlock_t *)addr_sb_lock);<br> printk("<0>----------------->%d\n",count);<br> return 0;<br>}<br><br><br>static __exit void sbinfo_exit(void)<br>
{<br> printk("<0> bye! \n");<br>}<br><br>module_init(sbinfo_init);<br>module_exit(sbinfo_exit);<br>MODULE_LICENSE("GPL");<br><br>and output:<br>[ 4196.218726] filesystem name:sysfs<br>[ 4196.218732] filesystem name:rootfs<br>
[ 4196.218735] filesystem name:bdev<br>[ 4196.218737] filesystem name:proc<br>[ 4196.218740] filesystem name:tmpfs<br>[ 4196.218742] filesystem name:devtmpfs<br>[ 4196.218745] filesystem name:debugfs<br>[ 4196.218747] filesystem name:sockfs<br>
[ 4196.218750] filesystem name:pipefs<br>[ 4196.218752] filesystem name:anon_inodefs<br>[ 4196.218755] filesystem name:securityfs<br>[ 4196.218757] filesystem name:devpts<br>[ 4196.218760] filesystem name:hugetlbfs<br>[ 4196.218762] filesystem name:mqueue<br>
[ 4196.218765] filesystem name:sysfs<br>[ 4196.218767] filesystem name:fusectl<br>[ 4196.218769] filesystem name:ext4<br>[ 4196.218771] filesystem name:tmpfs<br>[ 4196.218774] filesystem name:tmpfs<br>[ 4196.218776] filesystem name:tmpfs<br>
[ 4196.218778] filesystem name:ext4<br>[ 4196.218780] filesystem name:fuse<br>[ 4196.218783] filesystem name:binfmt_misc<br>[ 4196.218786] ----------------->23<br><br>and cat /proc/filesystems output:<br>nodev sysfs<br>
nodev rootfs<br>nodev bdev<br>nodev proc<br>nodev cgroup<br>nodev cpuset<br>nodev tmpfs<br>nodev devtmpfs<br>nodev debugfs<br>nodev securityfs<br>nodev sockfs<br>nodev pipefs<br>nodev anon_inodefs<br>
nodev devpts<br> ext3<br> ext2<br> ext4<br>nodev ramfs<br>nodev hugetlbfs<br>nodev ecryptfs<br>nodev fuse<br> fuseblk<br>nodev fusectl<br>nodev pstore<br>
nodev mqueue<br>nodev binfmt_misc<br><br>if anyone knows please help .Thanks<br>-- <br><div>----------------------------------------------------------------------------------------------</div><div>WangZhe Xi'an Shanxi CHINA</div>
<div>qq 785924174</div><div>blog <a href="http://blog.163.com/zhe_wang_2009" target="_blank">blog.163.com/zhe_wang_2009</a></div><div>----------------------------------------------------------------------------------------------</div>