zoukankan      html  css  js  c++  java
  • day3 文件系统 内核模块 ctags

    nfs网络文件系统  

    smb   修改配置文件  sudo  vim /etc/samba/smb.conf    重启服务   /etc/init.d/samba restart

    自制小的文件系统

    1.编译内核;2动态加载模块

    mydev.c

    #include<linux/init.h>
    #include<linux/module.h>
    #include<linux/kernel.h>
    #include<linux/fs.h>
    #include<linux/cdev.h>
    
    static struct cdev my_cdev;//内核内部使用struct cdev结构代表字符设备
    static int my_dev_major=350;
    static dev_t my_devno;
    
    
    int hello_open(struct inode *pnode,struct file *filp)//funcation
    {
        printk(KERN_NOTICE "<1> hello");
    }
    static struct file_operations my_cdev_ops={  //operations
        .open=hello_open,};
    
    int my_proc_init(void)
    {
        my_devno=MKDEV(my_dev_major,0);//number of dev
        register_chrdev_region(my_devno,1,"my_cdev");//register qudong chengxu 在建立字符设备驱动时首先要获取设备号
        
        cdev_init(&my_cdev,&my_cdev_ops);//内核在内部使用类型 struct cdev 的结构来代表字符设备,初始化一个字符设备
        cdev_add(&my_cdev,my_devno,1);//cdev 结构建立, 最后的步骤是把它告诉内核
    }
    static void test(void)
    {
        return 0;
    //    printk("bye");
    }
    
    module_init(my_proc_init);
    module_exit(test);
    MODULE_LICENSE("GPL");

    Makefile:

    obj-m:=mydev.o #obj-m:=说明要使用mydev.o建立一个模块
    CURRENT_PATH:=$(shell pwd)
    LINUX_KERNEL:=$(shell uname -r)
    LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)
    
    all:
        make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
    clean:
        make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean

    参考链接:写一个简单的字符设备驱动http://blog.csdn.net/haomcu/article/details/44620725

    HelloWorld 模块http://www.cnblogs.com/main-xlg/p/4042667.html

    module_init();

    module_exit()

    obj-m +=

    make -C       //http://blog.sina.com.cn/s/blog_89fa41ef0100trjr.html

    insmod  ***.ko

    lsmod展示动态加载的模块

    sudo rmmod  ××   //注销

    #include<linux/init.h>

    #include<linux/fs.h>

    #include<cdev.h>

    #Include<linux/module.h>

    static struct cdev my_cdev;

    static int my_dev_major=350;

    static dev_t my_devno;

    int hello_open(  struct inode *pnode,struct file *pfile)

    {ptintk("hello");  }

    static struct file_operations my_cdev_ops={

      .open=hello_open,}

    int my_proc_init(void)

    {

     my_devno=MKDEV(my_dev_major,0);

      register_chrdev_region(my_devno,1,"hello");

     

     cdev_init(&my_cdev,&my_cdev_ops);

      cdev_add(&my_dev,my_devno,1);//注册

    }

    sudo mknod my_dev c 350 0

    stat my_dev

     ctags: 

    http://www.cnblogs.com/chijianqiang/archive/2012/12/17/vim-4.html

    多种插件:http://blog.csdn.net/bokee/article/details/6633193

    make tags

    set tags=/usr/

    编译内核:http://www.cnblogs.com/wang_yb/p/3899439.html

  • 相关阅读:
    NND,优酷效果实在太差了
    技术人员创业的短板
    【上架通知】天轰穿.NET4趣味编程视频教程VS2010轻松学习C#零基础
    最新课程信息 课堂风格视频教程,中规中矩的教学思路设计和插诨打科的讲解方式
    Visual Studio 2010 Ultimate 中文旗舰版——提供下载地址和KEY
    整整半个月了
    学云网五一特惠活动,很喜感的图
    学员就业>我心纠结
    委托的定义和使用入门天轰穿
    第八 讲 : 流程控制循环语句 【天轰穿.Net4趣味编程系列视频教程vs2010轻松学习C#】
  • 原文地址:https://www.cnblogs.com/degrone/p/4932483.html
Copyright © 2011-2022 走看看