compatmac.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * mtd/include/compatmac.h
  3.  *
  4.  * $Id: compatmac.h,v 1.4 2000/07/03 10:01:38 dwmw2 Exp $
  5.  *
  6.  * Extensions and omissions from the normal 'linux/compatmac.h'
  7.  * files. hopefully this will end up empty as the 'real' one 
  8.  * becomes fully-featured.
  9.  */
  10. /* First, include the parts which the kernel is good enough to provide 
  11.  * to us 
  12.  */
  13.    
  14. #ifndef __LINUX_MTD_COMPATMAC_H__
  15. #define __LINUX_MTD_COMPATMAC_H__
  16. #include <linux/compatmac.h>
  17. #include <linux/types.h> /* used later in this header */
  18. #include <linux/module.h>
  19. #ifndef LINUX_VERSION_CODE
  20. #include <linux/version.h>
  21. #endif
  22. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
  23. #include <linux/vmalloc.h>
  24. #endif
  25. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,0)
  26. #  error "This kernel is too old: not supported by this file"
  27. #endif
  28. /* Modularization issues */
  29. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,18)
  30. #  define __USE_OLD_SYMTAB__
  31. #  define EXPORT_NO_SYMBOLS register_symtab(NULL);
  32. #  define REGISTER_SYMTAB(tab) register_symtab(tab)
  33. #else
  34. #  define REGISTER_SYMTAB(tab) /* nothing */
  35. #endif
  36. #ifdef __USE_OLD_SYMTAB__
  37. #  define __MODULE_STRING(s)         /* nothing */
  38. #  define MODULE_PARM(v,t)           /* nothing */
  39. #  define MODULE_PARM_DESC(v,t)      /* nothing */
  40. #  define MODULE_AUTHOR(n)           /* nothing */
  41. #  define MODULE_DESCRIPTION(d)      /* nothing */
  42. #  define MODULE_SUPPORTED_DEVICE(n) /* nothing */
  43. #endif
  44. /*
  45.  * "select" changed in 2.1.23. The implementation is twin, but this
  46.  * header is new
  47.  */
  48. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,22)
  49. #  include <linux/poll.h>
  50. #else
  51. #  define __USE_OLD_SELECT__
  52. #endif
  53. /* Other change in the fops are solved using pseudo-types */
  54. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
  55. #  define lseek_t      long long
  56. #  define lseek_off_t  long long
  57. #else
  58. #  define lseek_t      int
  59. #  define lseek_off_t  off_t
  60. #endif
  61. /* changed the prototype of read/write */
  62. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0) || defined(__alpha__)
  63. # define count_t unsigned long
  64. # define read_write_t long
  65. #else
  66. # define count_t int
  67. # define read_write_t int
  68. #endif
  69. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,31)
  70. # define release_t void
  71. #  define release_return(x) return
  72. #else
  73. #  define release_t int
  74. #  define release_return(x) return (x)
  75. #endif
  76. #if LINUX_VERSION_CODE < 0x20300
  77. #define __exit
  78. #endif
  79. #if LINUX_VERSION_CODE < 0x20200
  80. #define __init
  81. #else
  82. #include <linux/init.h>
  83. #endif
  84. #if LINUX_VERSION_CODE < 0x20300
  85. #define init_MUTEX(x) do {*(x) = MUTEX;} while (0)
  86. #define RQFUNC_ARG void
  87. #define blkdev_dequeue_request(req) do {CURRENT = req->next;} while (0)
  88. #else
  89. #define RQFUNC_ARG request_queue_t *q
  90. #endif
  91. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,0)
  92. #define __MOD_INC_USE_COUNT(mod)                                        
  93.         (atomic_inc(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED|MOD_USED_ONCE)
  94. #define __MOD_DEC_USE_COUNT(mod)                                        
  95.         (atomic_dec(&(mod)->uc.usecount), (mod)->flags |= MOD_VISITED)
  96. #endif
  97. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
  98. #define DECLARE_WAIT_QUEUE_HEAD(x) struct wait_queue *x = NULL
  99. #define init_waitqueue_head init_waitqueue
  100. static inline int try_inc_mod_count(struct module *mod)
  101. {
  102. if (mod)
  103. __MOD_INC_USE_COUNT(mod);
  104. return 1;
  105. }
  106. #endif
  107. /* Yes, I'm aware that it's a fairly ugly hack.
  108.    Until the __constant_* macros appear in Linus' own kernels, this is
  109.    the way it has to be done.
  110.  DW 19/1/00
  111.  */
  112. #include <asm/byteorder.h>
  113. #ifndef __constant_cpu_to_le16
  114. #ifdef __BIG_ENDIAN
  115. #define __constant_cpu_to_le64(x) ___swab64((x))
  116. #define __constant_le64_to_cpu(x) ___swab64((x))
  117. #define __constant_cpu_to_le32(x) ___swab32((x))
  118. #define __constant_le32_to_cpu(x) ___swab32((x))
  119. #define __constant_cpu_to_le16(x) ___swab16((x))
  120. #define __constant_le16_to_cpu(x) ___swab16((x))
  121. #define __constant_cpu_to_be64(x) ((__u64)(x))
  122. #define __constant_be64_to_cpu(x) ((__u64)(x))
  123. #define __constant_cpu_to_be32(x) ((__u32)(x))
  124. #define __constant_be32_to_cpu(x) ((__u32)(x))
  125. #define __constant_cpu_to_be16(x) ((__u16)(x))
  126. #define __constant_be16_to_cpu(x) ((__u16)(x))
  127. #else
  128. #ifdef __LITTLE_ENDIAN
  129. #define __constant_cpu_to_le64(x) ((__u64)(x))
  130. #define __constant_le64_to_cpu(x) ((__u64)(x))
  131. #define __constant_cpu_to_le32(x) ((__u32)(x))
  132. #define __constant_le32_to_cpu(x) ((__u32)(x))
  133. #define __constant_cpu_to_le16(x) ((__u16)(x))
  134. #define __constant_le16_to_cpu(x) ((__u16)(x))
  135. #define __constant_cpu_to_be64(x) ___swab64((x))
  136. #define __constant_be64_to_cpu(x) ___swab64((x))
  137. #define __constant_cpu_to_be32(x) ___swab32((x))
  138. #define __constant_be32_to_cpu(x) ___swab32((x))
  139. #define __constant_cpu_to_be16(x) ___swab16((x))
  140. #define __constant_be16_to_cpu(x) ___swab16((x))
  141. #else
  142. #error No (recognised) endianness defined (unless it,s PDP)
  143. #endif /* __LITTLE_ENDIAN */
  144. #endif /* __BIG_ENDIAN */
  145. #endif /* ifndef __constant_cpu_to_le16 */
  146. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
  147.   #define mod_init_t int  __init
  148.   #define mod_exit_t void  
  149. #else
  150.   #define mod_init_t static int __init
  151.   #define mod_exit_t static void __exit
  152. #endif
  153. #ifndef THIS_MODULE
  154. #ifdef MODULE
  155. #define THIS_MODULE (&__this_module)
  156. #else
  157. #define THIS_MODULE (NULL)
  158. #endif
  159. #endif
  160. #if LINUX_VERSION_CODE < 0x20300
  161. #include <linux/interrupt.h>
  162. #define spin_lock_bh(lock) do {start_bh_atomic();spin_lock(lock);} while(0)
  163. #define spin_unlock_bh(lock) do {spin_unlock(lock);end_bh_atomic();} while(0)
  164. #else
  165. #include <asm/softirq.h>
  166. #include <linux/spinlock.h>
  167. #endif
  168. #endif /* __LINUX_MTD_COMPATMAC_H__ */