Chinaunix首页 | 论坛 | 博客
  • 博客访问: 186290
  • 博文数量: 37
  • 博客积分: 171
  • 博客等级: 入伍新兵
  • 技术积分: 315
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-13 22:54
个人简介

寻找方向程序猿、攻城狮

文章存档

2023年(1)

2022年(4)

2019年(1)

2018年(1)

2017年(1)

2015年(2)

2014年(19)

2013年(2)

2012年(1)

2011年(5)

分类: LINUX

2014-04-08 23:30:23



  1. /*
  2.  * Space.c    Defines which protocol modules and I/O device drivers get
  3.  *        linked into the LINUX kernel. Currently, this is only used
  4.  *        by the NET layer of LINUX, but it eventually might move to
  5.  *        an upper directory of the system.
  6.  *
  7.  * Version:    @(#)Space.c    1.0.2    04/22/93
  8.  *
  9.  * Author:    Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  10.  */
  11. /*Space.c    定义了当前链接到LINUX Kernel的协议模块和I/O设备驱动。当前仅有LINUX的网络层使用,但它最后会在整个系统中使用。*/
  12. #include <linux/config.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/ddi.h>


  16. #define CONFIG_UNIX        YES        /* always present...    */


  17. /*
  18.  * Section A:    Networking Protocol Handlers.
  19.  *        This section defines which networking protocols get
  20.  *        linked into the SOCKET layer of the Linux kernel.
  21.  *        Currently, these are AF_UNIX (always) and AF_INET.
  22.  */
  23. /*Section A: 网络协议管理器.
  24.  *    定义了链接到Linux内核的SOCKET层的网络协议。当前有AF_UNIX和AF_INET
  25. */
  26. #ifdef    CONFIG_UNIX
  27. # include "unix/unix.h"
  28. #endif
  29. #ifdef    CONFIG_INET
  30. # include "inet/inet.h"
  31. #endif
  32. #ifdef CONFIG_IPX
  33. #include "inet/ipxcall.h"
  34. #endif
  35. #ifdef CONFIG_AX25
  36. #include "inet/ax25call.h"
  37. #endif

/*定义了全局protocols数组,将在ddi.c中被调用*/

  1. struct ddi_proto protocols[] = {
  2. #ifdef    CONFIG_UNIX
  3.   { "UNIX",    unix_proto_init    },
  4. #endif
  5. #ifdef CONFIG_IPX
  6.   { "IPX",    ipx_proto_init },
  7. #endif
  8. #ifdef CONFIG_AX25
  9.   { "AX.25",    ax25_proto_init },
  10. #endif
  11. #ifdef    CONFIG_INET
  12.   { "INET",    inet_proto_init    },
  13. #endif
  14.   { NULL,    NULL        }
  15. };


  16. /*
  17.  * Section B:    Device Driver Modules.
  18.  *        This section defines which network device drivers
  19.  *        get linked into the Linux kernel. It is currently
  20.  *        only used by the INET protocol. Any takers for the
  21.  *        other protocols like XNS or Novell?
  22.  *
  23.  * WARNING:    THIS SECTION IS NOT YET USED BY THE DRIVERS !!!!!
  24.  */
  25. /* Section B:    设备驱动模块
  26.  *        定义了哪些网络设备驱动链接到Linux内核。当前仅被INET协议使用。
  27.  *警告:    当前还没有驱动使用这儿定义的数据
  28.  *
  29.  **/
  30. /*#include "drv/we8003/we8003.h"    Western Digital WD-80[01]3    */
  31. /*#include "drv/dp8390/dp8390.h"    Donald Becker's DP8390 kit    */
  32. /*#inclde "drv/slip/slip.h"        Laurence Culhane's SLIP kit    */

  33. /*定义全局的devices数组,在ddi.c中使用*/
  34. struct ddi_device devices[] = {
  35. #if CONF_WE8003
  36.   { "WD80x3[EBT]",
  37.     "",    0,    1,    we8003_init,    NULL,
  38.     19,    0,    DDI_FCHRDEV,
  39.     { 0x280,    0,    15,    0,    32768,    0xD0000        }    },
  40. #endif
  41. #if CONF_DP8390
  42.   { "DP8390/WD80x3",
  43.     "",    0,    1,    dpwd8003_init,    NULL,
  44.     20,    0,    DDI_FCHRDEV,
  45.     {    0,    0,    0,    0,    0,    0,        }    },
  46.   { "DP8390/NE-x000",
  47.     "",    0,    1,    dpne2000_init,    NULL,
  48.     20,    8,    DDI_FCHRDEV,
  49.     {    0,    0,    0,    0,    0,    0,        }    },
  50.   { "DP8390/3C50x",
  51.     "",    0,    1,    dpec503_init,    NULL,
  52.     20,    16,    DDI_FCHRDEV,
  53.     {    0,    0,    0,    0,    0,    0,        }    },
  54. #endif
  55.   { NULL,
  56.     "",    0,    0,    NULL,        NULL,
  57.     0,    0,    0,
  58.     {    0,    0,    0,    0,    0,    0        }    }
  59. };

  1. /*
  2.  * UNIX        An implementation of the AF_UNIX network domain for the
  3.  *        LINUX operating system. UNIX is implemented using the
  4.  *        BSD Socket interface as the means of communication with
  5.  *        the user level.
  6.  *
  7.  *        This file descibes some things of the UNIX protocol family
  8.  *        module. It is mainly used for the "proc" sub-module now,
  9.  *        but it may be useful for cleaning up the UNIX module as a
  10.  *        whole later.
  11.  *
  12.  * UNIX    LINUX操作系统的AF_UNIX网络域的实现。UNIX使用BSD Socket接口作为其与用户空间程序通信来实现的。这个文件描述了UNIX协议族模块的一些东西
  13.  *        它目前主要用于“proc”子模块,但它迟些对于整体清除UNIX模块可能是有用的(这一句不知道是什么意思)。
  14.  *
  15.  *
  16.  *
  17.  * Version:    @(#)unix.h    1.0.3    05/25/93
  18.  *
  19.  * Authors:    Orest Zborowski, <obz@Kodak.COM>
  20.  *        Ross Biro, <bir7@leland.Stanford.Edu>
  21.  *        Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  22.  *
  23.  * Fixes:
  24.  *        Dmitry Gorodchanin    -    proc locking
  25.  *
  26.  *        This program is free software; you can redistribute it and/or
  27.  *        modify it under the terms of the GNU General Public License
  28.  *        as published by the Free Software Foundation; either version
  29.  *        2 of the License, or (at your option) any later version.
  30.  */


  31. #ifdef _LINUX_UN_H /*在内核代码的include/linux/un.h中定义*/

  32. /*存储AF_UNIX协议数据的数据结构,其中个别成员还不知道含义,等后面再补全*/
  33. struct unix_proto_data {
  34.     int        refcnt;        /* cnt of reference 0=free    *//*引用计数*/
  35.                     /* -1=not initialised    -bgm    */
  36.     struct socket    *socket;    /* socket we're bound to    *//*绑定的socket*/
  37.     int        protocol;
  38.     struct sockaddr_un    sockaddr_un; /*绑定地址*/
  39.     short        sockaddr_len;    /* >0 if name bound        */
  40.     char        *buf;
  41.     int        bp_head, bp_tail;
  42.     struct inode    *inode;
  43.     struct unix_proto_data    *peerupd;
  44.     struct wait_queue *wait;    /* Lock across page faults (FvK) */
  45.     int        lock_flag;
  46. };

  47. extern struct unix_proto_data unix_datas[NSOCKETS]; /*全局数组声明,该数组大小代表着所能创建的UNIX套接字的个数,在net/unix/sock.c中定义*/


  48. #define last_unix_data        (unix_datas + NSOCKETS - 1)


  49. #define UN_DATA(SOCK)         ((struct unix_proto_data *)(SOCK)->data)
  50. #define UN_PATH_OFFSET        ((unsigned long)((struct sockaddr_un *)0) \
  51.                             ->sun_path)

  52. /*
  53.  * Buffer size must be power of 2. buffer mgmt inspired by pipe code.
  54.  * note that buffer contents can wraparound, and we can write one byte less
  55.  * than full size to discern full vs empty.
  56.  */
  57. /*缓冲区大小必须是2的冥数。buffer mgmt inspired by pipe code.note that buffer contents can wraparound,我们能够写一个字节,这比总大小要小,
  58. 来判断缓冲区是满还是空*/
  59. #define BUF_SIZE        PAGE_SIZE /*缓冲区大小等于一个内存页面大小*/
  60. #define UN_BUF_AVAIL(UPD)    (((UPD)->bp_head - (UPD)->bp_tail) & \
  61.                                 (BUF_SIZE-1))   /*计算缓冲区中可用大小*/
  62. #define UN_BUF_SPACE(UPD)    ((BUF_SIZE-1) - UN_BUF_AVAIL(UPD)) /*这个应该是计算已用大小?*/

  63. #endif    /* _LINUX_UN_H */


  64. extern void    unix_proto_init(struct ddi_proto *pro); /*系统启动时初始化调用该函数,在ddi.c中*/


  1. /*
  2.  * INET        An implementation of the TCP/IP protocol suite for the LINUX
  3.  *        operating system. INET is implemented using the BSD Socket
  4.  *        interface as the means of communication with the user level.
  5.  *
  6.  *        General Definitions for the TCP/IP (INET) module. This is
  7.  *        mostly a bunch of "general" macros, plus the PROTOCOL link
  8.  *        code and data.
  9.  *        LINUX操作系统的TCP/IP协议簇的实现。INET的实现,使用BSD Socket接口,作为与用户空间通信的手段。
  10.  *        TCP/IP(INET)模块的通用定义。This is mostly a bunch of "general" macros, plus the PROTOCOL link code and data.
  11.  *
  12.  * Version:    @(#)inet.h    1.0.6    05/25/93
  13.  *
  14.  * Author:    Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  15.  *
  16.  *        This work was derived friom Ross Biro's inspirational work
  17.  *        for the LINUX operating system. His version numbers were:
  18.  *
  19.  *        $Id: Space.c,v 0.8.4.5 1992/12/12 19:25:04 bir7 Exp $
  20.  *        $Id: arp.c,v 0.8.4.6 1993/01/28 22:30:00 bir7 Exp $
  21.  *        $Id: arp.h,v 0.8.4.6 1993/01/28 22:30:00 bir7 Exp $
  22.  *        $Id: dev.c,v 0.8.4.13 1993/01/23 18:00:11 bir7 Exp $
  23.  *        $Id: dev.h,v 0.8.4.7 1993/01/23 18:00:11 bir7 Exp $
  24.  *        $Id: eth.c,v 0.8.4.4 1993/01/22 23:21:38 bir7 Exp $
  25.  *        $Id: eth.h,v 0.8.4.1 1992/11/10 00:17:18 bir7 Exp $
  26.  *        $Id: icmp.c,v 0.8.4.9 1993/01/23 18:00:11 bir7 Exp $
  27.  *        $Id: icmp.h,v 0.8.4.2 1992/11/15 14:55:30 bir7 Exp $
  28.  *         $Id: ip.c,v 0.8.4.8 1992/12/12 19:25:04 bir7 Exp $
  29.  *         $Id: ip.h,v 0.8.4.2 1993/01/23 18:00:11 bir7 Exp $
  30.  *         $Id: loopback.c,v 0.8.4.8 1993/01/23 18:00:11 bir7 Exp $
  31.  *         $Id: packet.c,v 0.8.4.7 1993/01/26 22:04:00 bir7 Exp $
  32.  *        $Id: protocols.c,v 0.8.4.3 1992/11/15 14:55:30 bir7 Exp $
  33.  *        $Id: raw.c,v 0.8.4.12 1993/01/26 22:04:00 bir7 Exp $
  34.  *        $Id: sock.c,v 0.8.4.6 1993/01/28 22:30:00 bir7 Exp $
  35.  *        $Id: sock.h,v 0.8.4.7 1993/01/26 22:04:00 bir7 Exp $
  36.  *        $Id: tcp.c,v 0.8.4.16 1993/01/26 22:04:00 bir7 Exp $
  37.  *        $Id: tcp.h,v 0.8.4.7 1993/01/22 22:58:08 bir7 Exp $
  38.  *        $Id: timer.c,v 0.8.4.8 1993/01/23 18:00:11 bir7 Exp $
  39.  *        $Id: timer.h,v 0.8.4.2 1993/01/23 18:00:11 bir7 Exp $
  40.  *        $Id: udp.c,v 0.8.4.12 1993/01/26 22:04:00 bir7 Exp $
  41.  *        $Id: udp.h,v 0.8.4.1 1992/11/10 00:17:18 bir7 Exp $
  42.  *        $Id: we.c,v 0.8.4.10 1993/01/23 18:00:11 bir7 Exp $
  43.  *        $Id: wereg.h,v 0.8.4.1 1992/11/10 00:17:18 bir7 Exp $
  44.  *
  45.  *        This program is free software; you can redistribute it and/or
  46.  *        modify it under the terms of the GNU General Public License
  47.  *        as published by the Free Software Foundation; either version
  48.  *        2 of the License, or (at your option) any later version.
  49.  */
  50. #ifndef _INET_H
  51. #define _INET_H


  52. #include <linux/ddi.h>


  53. #define NET16(x)    ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00)) /*调换x的低8位和高8位的位置*/


  54. #undef    INET_DEBUG
  55. #ifdef    INET_DEBUG
  56. # define    DPRINTF(x)    dprintf x
  57. #else
  58. # define    DPRINTF(x)    do ; while (0)
  59. #endif
/*调试级别。每个模块一个。*/
  1. /* Debug levels. One per module. */
  2. #define DBG_OFF        0            /* no debugging        */
  3. #define DBG_INET    1            /* sock.c        */
  4. #define DBG_RT        2            /* route.c        */
  5. #define DBG_DEV        3            /* dev.c        */
  6. #define DBG_ETH        4            /* eth.c        */
  7. #define DBG_PROTO    5            /* protocol.c        */
  8. #define DBG_TMR        6            /* timer.c        */
  9. #define DBG_PKT        7            /* packet.c        */
  10. #define DBG_RAW        8            /* raw.c        */

  11. #define DBG_LOOPB    10            /* loopback.c        */
  12. #define DBG_SLIP    11            /* slip.c        */

  13. #define DBG_ARP        20            /* arp.c        */
  14. #define DBG_IP        21            /* ip.c            */
  15. #define DBG_ICMP    22            /* icmp.c        */
  16. #define DBG_TCP        23            /* tcp.c        */
  17. #define DBG_UDP        24            /* udp.c        */


  18. extern int        inet_debug;


  19. extern void        inet_proto_init(struct ddi_proto *pro); /*inet协议簇的初始化函数*/
  20. extern char        *in_ntoa(unsigned long in);
  21. extern unsigned long    in_aton(char *str);

  22. extern void        dprintf(int level, char *fmt, ...);

  23. extern int        dbg_ioctl(void *arg, int level);

  24. #endif    /* _INET_H */


  1. #ifndef _LINUX_UN_H
  2. #define _LINUX_UN_H
        
        /*定义UNIX套接字对应的地址信息*/
  1. struct sockaddr_un {
  2.     unsigned short sun_family;    /* AF_UNIX */
  3.     char sun_path[108];        /* pathname */
  4. };

  5. #endif /* _LINUX_UN_H */


阅读(1925) | 评论(0) | 转发(0) |
0

上一篇:mknod命令的作用

下一篇:SDIO接口

给主人留下些什么吧!~~