LinuxÄÚºË̬ϵÄÎļþ²Ù×÷
ÔÚVFSµÄÖ§³ÖÏ£¬Óû§Ì¬½ø³Ì¶ÁдÈκÎÀàÐ͵ÄÎļþϵͳ¶¼¿ÉÒÔʹÓÃreadºÍwrite×ÅÁ½¸öϵͳµ÷Ó㬵«ÊÇÔÚlinuxÄÚºËÖÐûÓÐÕâÑùµÄϵͳµ÷ÓÃÎÒÃÇÈçºÎ²Ù×÷ÎļþÄØ£¿ÎÒÃÇÖªµÀreadºÍwriteÔÚ½øÈëÄÚºË̬֮ºó£¬Êµ¼ÊÖ´ÐеÄÊÇsys_readºÍsys_write£¬µ«ÊDz鿴ÄÚºËÔ´´úÂ룬·¢ÏÖÕâЩ²Ù×÷ÎļþµÄº¯Êý¶¼Ã»Óе¼³ö(ʹÓÃEXPORT_SYMBOLµ¼³ö)£¬Ò²¾ÍÊÇ˵ÔÚÄÚºËÄ£¿éÖÐÊDz»ÄÜʹÓõģ¬ÄÇÈçºÎÊǺã¿
ͨ¹ý²é¿´sys_openµÄÔ´ÂëÎÒÃÇ·¢ÏÖ£¬ÆäÖ÷ҪʹÓÃÁËdo_filp_open()º¯Êý£¬¸Ãº¯ÊýÔÚfs/namei.cÖУ¬¶øÔÚ¸ÄÎļþÖУ¬filp_openº¯ÊýÒ²Êǵ÷ÓÃÁËdo_filp_openº¯Êý£¬²¢ÇÒ½Ó¿ÚºÍsys_openº¯Êý¼«ÎªÏàËÆ£¬µ÷ÓòÎÊýÒ²ºÍsys_openÒ»Ñù£¬²¢ÇÒʹÓÃEXPORT_SYMBOLµ¼³öÁË£¬ËùÒÔÎÒÃDzÂÏë¸Ãº¯Êý¿ÉÒÔ´ò¿ªÎļþ£¬¹¦ÄܺÍopenÒ»Ñù¡£Ê¹ÓÃͬÑùµÄ²éÕÒ·½·¨£¬ÎÒÃÇÕÒ³öÁËÒ»×éÔÚÄÚºËÖвÙ×÷ÎļþµÄº¯Êý£¬ÈçÏ£º
¹¦ÄÜ
º¯ÊýÔÐÍ
´ò¿ªÎļþ
struct file *filp_open(const char *filename, int flags, int mode)
¶ÁÈ¡Îļþ
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
дÎļþ
ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
¹Ø±ÕÎļþ
int filp_close(struct file *filp, fl_owner_t id)
ÎÒÃÇ×¢Òâµ½ÔÚvfs_readºÍvfs_writeº¯ÊýÖУ¬Æä²ÎÊýbufÖ¸ÏòµÄÓû§¿Õ¼äµÄÄÚ´æµØÖ·£¬Èç¹ûÎÒÃÇÖ±½ÓʹÓÃÄں˿ռäµÄÖ¸Õ룬Ôò»á·µ»Ø-EFALUT¡£ËùÒÔÎÒÃÇÐèҪʹÓÃ
set_fs()ºÍget_fs()ºêÀ´¸Ä±äÄں˶ÔÄÚ´æµØÖ·¼ì²éµÄ´¦Àí·½Ê½£¬ËùÒÔÔÚÄں˿ռä¶ÔÎļþµÄ¶ÁдÁ÷³ÌΪ£º
mm_segment_t fs = get_fs();
set_fs(KERNEL_FS);
//vfs_write();
vfs_read();
set_fs(fs);
ÏÂÃæΪһ¸öÔÚÄÚºËÖжÔÎļþ²Ù×÷µÄÀý×Ó£º
#include
#include
#include
#include
static char buf[] = "ÄãºÃ";
static char buf1[10];
int __init hello_init(void)
{
struct file *fp;
mm_segment_t fs;
loff_t pos;
printk("hello enter\n");
fp = filp_open("/home/niutao/kernel_file", O_RDWR | O_CREAT, 0644);
if (IS_ERR(fp)) {
printk("create file error\n");
&
Ïà¹ØÎĵµ£º
Ó²Å̽ӿÚÊÇÓ²ÅÌÓëÖ÷»úϵͳ¼äµÄÁ¬½Ó²¿¼þ£¬×÷ÓÃÊÇÔÚÓ²ÅÌ»º´æºÍÖ÷»úÄÚ´æÖ®¼ä´«ÊäÊý¾Ý¡£²»Í¬µÄÓ²Å̽ӿھö¶¨×ÅÓ²ÅÌÓë¼ÆËã»úÖ®¼äµÄÁ¬½ÓËٶȣ¬ÔÚÕû¸öϵͳÖУ¬Ó²Å̽ӿڵÄÓÅÁÓÖ±½ÓÓ°Ïì×ųÌÐòÔËÐпìÂýºÍϵͳÐÔÄܺûµ¡£´ÓÕûÌåµÄ½Ç¶ÈÉÏ£¬Ó²Å̽ӿڷÖΪIDE¡¢SATA¡¢SCSIºÍ¹âÏËͨµÀËÄÖÖ£¬IDE½Ó¿ÚÓ²Å̶àÓÃÓÚ¼ÒÓòúÆ·ÖУ¬Ò²²¿·ÖÓ¦ÓÃÓÚ· ......
ÔÚ°²×°ÍêjdkÒԺ󣬾ÍÀ´°²×°MyEclipseÁË¡£
ÓÐһЩ°²×°ÁËjdkÒÔºóûÓÐÉúЧ£¬³öÏֵĻ¹ÊÇ1.4°æ±¾µÄ¡£
ËùÒÔ°²×°MyEclipse7.0»òÕßÊÇ6.5¡¢6.6µÄ¶¼»á³ö´í
[root@gupt aaaa]# ll
×ÜÓÃÁ¿ 380
dr-xr-xr-x 6 root root 4096
2009-01-17 configuration
-r--r--r-- 1 root root 7 ......
man¾ÍÊÇmanualµÄËõд£¬ÓÃÀ´²é¿´ÏµÍ³ÖÐ×Ô´øµÄ¸÷Öֲο¼Êֲᡣ
Ò»¡¢ËµÃ÷
1£¬ÊÖ²áÒ³·ÖΪºÃ¼¸¸ö²¿·Ö£¬ÈçÏÂËùʾ£º
1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File fo ......
1. gccµÄ__attribute__±àÒïÊôÐÔ
ÒªÁ˽âLinux Kernel´úÂëµÄ·Ö¶ÎÐÅÏ¢£¬ÐèÒªÁ˽âÒ»ÏÂgccµÄ__attribute__µÄ±àÒïÊôÐÔ£¬__attribute__Ö÷ÒªÓÃÓڸıäËùÉùÃ÷»ò¶¨ÒåµÄº¯Êý»òÊý¾ÝµÄÌØÐÔ£¬ËüÓкܶà×ÓÏÓÃÓڸıä×÷ÓöÔÏóµÄÌØÐÔ¡£±ÈÈç¶Ôº¯Êý£¬noline½«½ûÖ¹½øÐÐÄÚÁªÀ©Õ¹¡¢noreturn±íʾûÓзµ»ØÖµ¡¢pure±íÃ÷º¯Êý³ý·µ»ØÖµÍ⣬²»»áͨ¹ýÆäËü ......
ÔÚijЩÌØÊâµÄÇé¿öÏ£¬ÈçÒòΪÍøÂç»òÕßXÅäÖõĹØϵÎÞ·¨Á¬½Óµ½X server»òÕßÖ÷»úÉÏûÓÐX£¬¾Í¿ÉÒÔʹÓþ²Ä¬°²×°µÄ·½Ê½°²×°Êý¾Ý¿â£¬Í¬ÑùÈç¹ûÐèÒª´ó¹æÄ£²¿Êð£¬Ôò¾²Ä¬°²×°½«»á´ó´ó¼õÇáDBAµÄÖظ´ÀͶ¯Á¦£¬¶øÇÒ¾²Ä¬°²×°²»ÐèÒªX£¬´Ó°²×°Ð§ÂÊ
ÔÚijЩÌØÊâµÄÇé¿öÏ£¬ÈçÒòΪÍøÂç»òÕßXÅäÖõĹØϵÎÞ·¨Á¬½Óµ½X server»òÕßÖ÷»úÉÏûÓÐX£ ......