Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
7.4 KiB

  1. /*
  2. * $Log: P:/user/amir/lite/vcs/flsystem.c_v $
  3. *
  4. * Rev 1.8 19 Aug 1997 20:04:16 danig
  5. * Andray's changes
  6. *
  7. * Rev 1.7 24 Jul 1997 18:11:48 amirban
  8. * Changed to flsystem.c
  9. *
  10. * Rev 1.6 07 Jul 1997 15:21:48 amirban
  11. * Ver 2.0
  12. *
  13. * Rev 1.5 29 Aug 1996 14:18:04 amirban
  14. * Less assembler
  15. *
  16. * Rev 1.4 18 Aug 1996 13:48:08 amirban
  17. * Comments
  18. *
  19. * Rev 1.3 09 Jul 1996 14:37:02 amirban
  20. * CPU_i386 define
  21. *
  22. * Rev 1.2 16 Jun 1996 14:02:38 amirban
  23. * Use int 1C instead of int 8
  24. *
  25. * Rev 1.1 09 Jun 1996 18:16:20 amirban
  26. * Added removeTimer
  27. *
  28. * Rev 1.0 20 Mar 1996 13:33:06 amirban
  29. * Initial revision.
  30. */
  31. /************************************************************************/
  32. /* */
  33. /* FAT-FTL Lite Software Development Kit */
  34. /* Copyright (C) M-Systems Ltd. 1995-1996 */
  35. /* */
  36. /************************************************************************/
  37. #include "flbase.h"
  38. #ifdef NT5PORT
  39. #include <ntddk.h>
  40. NTsocketParams driveInfo[SOCKETS];
  41. NTsocketParams * pdriveInfo = driveInfo;
  42. VOID *myMalloc(ULONG numberOfBytes)
  43. {
  44. return ExAllocatePool(NonPagedPool, numberOfBytes);
  45. }
  46. VOID timerInit(VOID) {};
  47. /* Wait for specified number of milliseconds */
  48. void flDelayMsecs(unsigned milliseconds)
  49. {
  50. unsigned innerLoop = 0xffffL;
  51. unsigned i,j;
  52. for(i = 0;i < milliseconds; i++){
  53. for(j = 0;j < innerLoop; j++){
  54. }
  55. }
  56. }
  57. #if POLLING_INTERVAL > 0
  58. VOID (*intervalRoutine_flsystem)(VOID);
  59. ULONG timerInterval_flsystem;
  60. extern KTIMER timerObject;
  61. extern KDPC timerDpc;
  62. extern BOOLEAN timerWasStarted;
  63. VOID timerRoutine(
  64. IN PKDPC Dpc,
  65. IN PVOID DeferredContext,
  66. IN PVOID SystemArgument1,
  67. IN PVOID SystemArgument2
  68. )
  69. {
  70. (*intervalRoutine_flsystem)();
  71. }
  72. /* Install an interval timer */
  73. FLStatus flInstallTimer(VOID (*routine)(VOID), unsigned intervalMsec)
  74. {
  75. intervalRoutine_flsystem = routine;
  76. timerInterval_flsystem = intervalMsec;
  77. KeInitializeDpc(&timerDpc, timerRoutine, NULL);
  78. KeInitializeTimer(&timerObject);
  79. startIntervalTimer();
  80. return flOK;
  81. }
  82. VOID startIntervalTimer(VOID)
  83. {
  84. LARGE_INTEGER dueTime;
  85. dueTime.QuadPart = -((LONG)timerInterval_flsystem * 10);
  86. KeSetTimerEx(&timerObject, dueTime, (LONG) timerInterval_flsystem, &timerDpc);
  87. timerWasStarted = TRUE;
  88. }
  89. #ifdef EXIT
  90. /* Remove an interval timer */
  91. VOID flRemoveTimer(VOID)
  92. {
  93. if (timerWasStarted) {
  94. KeCancelTimer(&timerObject);
  95. timerWasStarted = FALSE;
  96. }
  97. if (intervalRoutine_flsystem != NULL) {
  98. (*intervalRoutine_flsystem)(); /* Call it twice to shut down everything */
  99. (*intervalRoutine_flsystem)();
  100. intervalRoutine_flsystem = NULL;
  101. }
  102. }
  103. #endif /* EXIT */
  104. #endif /* POLLING_INTERVAL */
  105. /* Return current DOS time */
  106. unsigned flCurrentTime(VOID)
  107. {
  108. return 0; // not used
  109. }
  110. /* Return current DOS date */
  111. unsigned flCurrentDate(VOID)
  112. {
  113. return 0; // not used
  114. }
  115. VOID flSysfunInit(VOID)
  116. {
  117. timerInit();
  118. }
  119. /* Return a random number from 0 to 255 */
  120. unsigned flRandByte(VOID)
  121. {
  122. LARGE_INTEGER tickCount;
  123. KeQueryTickCount(&tickCount);
  124. return tickCount.LowPart & 0xff;
  125. }
  126. /*----------------------------------------------------------------------*/
  127. /* f l C r e a t e M u t e x */
  128. /* */
  129. /* Creates or initializes a mutex */
  130. /* */
  131. /* Parameters: */
  132. /* mutex : Pointer to mutex */
  133. /* */
  134. /* Returns: */
  135. /* FLStatus : 0 on success, otherwise failure */
  136. /*----------------------------------------------------------------------*/
  137. FLStatus flCreateMutex(FLMutex *mutex)
  138. {
  139. if(mutex){
  140. KeInitializeSpinLock(&mutex->Mutex);
  141. return flOK;
  142. }
  143. DEBUG_PRINT("Failed flCreateMutex()\n");
  144. return flGeneralFailure;
  145. }
  146. /*----------------------------------------------------------------------*/
  147. /* f l D e l e t e M u t e x */
  148. /* */
  149. /* Deletes a mutex. */
  150. /* */
  151. /* Parameters: */
  152. /* mutex : Pointer to mutex */
  153. /* */
  154. /*----------------------------------------------------------------------*/
  155. VOID flDeleteMutex(FLMutex *mutex)
  156. {
  157. }
  158. /*----------------------------------------------------------------------*/
  159. /* f l T a k e M u t e x */
  160. /* */
  161. /* Try to take mutex, if free. */
  162. /* */
  163. /* Parameters: */
  164. /* mutex : Pointer to mutex */
  165. /* */
  166. /* Returns: */
  167. /* int : TRUE = Mutex taken, FALSE = Mutex not free */
  168. /*----------------------------------------------------------------------*/
  169. FLBoolean flTakeMutex(FLMutex *mutex)
  170. {
  171. if(mutex){
  172. KeAcquireSpinLock(&mutex->Mutex, &mutex->cIrql );
  173. return TRUE;
  174. }
  175. DEBUG_PRINT("Failed flTakeMutex() on mutex\n");
  176. return FALSE;
  177. }
  178. /*----------------------------------------------------------------------*/
  179. /* f l F r e e M u t e x */
  180. /* */
  181. /* Free mutex. */
  182. /* */
  183. /* Parameters: */
  184. /* mutex : Pointer to mutex */
  185. /* */
  186. /*----------------------------------------------------------------------*/
  187. VOID flFreeMutex(FLMutex *mutex)
  188. {
  189. if(mutex){
  190. KeReleaseSpinLock(&mutex->Mutex, mutex->cIrql);
  191. }
  192. else{
  193. DEBUG_PRINT("Failed flFreeMutex() on mutex\n");
  194. }
  195. }
  196. UCHAR flInportb(unsigned portId)
  197. {
  198. return 0; // not used
  199. }
  200. VOID flOutportb(unsigned portId, UCHAR value)
  201. {
  202. // not used
  203. }
  204. /*----------------------------------------------------------------------*/
  205. /* f l A d d L o n g T o F a r P o i n t e r */
  206. /* */
  207. /* Add unsigned long offset to the far pointer */
  208. /* */
  209. /* Parameters: */
  210. /* ptr : far pointer */
  211. /* offset : offset in bytes */
  212. /* */
  213. /*----------------------------------------------------------------------*/
  214. VOID FAR0* flAddLongToFarPointer(VOID FAR0 *ptr, ULONG offset)
  215. {
  216. return ((VOID FAR0 *)((UCHAR FAR0*)ptr+offset));
  217. }
  218. #ifdef ENVIRONMENT_VARS
  219. void FAR0 * NAMING_CONVENTION flmemcpy(void FAR0* dest,const void FAR0 *src,size_t count)
  220. {
  221. size_t i;
  222. unsigned char FAR0 *ldest = (unsigned char FAR0 *)dest;
  223. const unsigned char FAR0 *lsrc = (unsigned char FAR0 *)src;
  224. for(i=0;( i < count );i++,ldest++,lsrc++)
  225. *(ldest) = *(lsrc);
  226. return dest;
  227. }
  228. void FAR0 * NAMING_CONVENTION flmemset(void FAR0* dest,int c,size_t count)
  229. {
  230. size_t i;
  231. unsigned char FAR0 *ldest = (unsigned char FAR0 *)dest;
  232. for(i=0;( i < count );i++,ldest++)
  233. *(ldest) = (unsigned char)c;
  234. return dest;
  235. }
  236. int NAMING_CONVENTION flmemcmp(const void FAR0* dest,const void FAR0 *src,size_t count)
  237. {
  238. size_t i;
  239. const unsigned char FAR0 *ldest = (unsigned char FAR0 *)dest;
  240. const unsigned char FAR0 *lsrc = (unsigned char FAR0 *)src;
  241. for(i=0;( i < count );i++,ldest++,lsrc++)
  242. if( *(ldest) != *(lsrc) )
  243. return (*(ldest)-*(lsrc));
  244. return 0;
  245. }
  246. #endif
  247. #endif /* NT5PORT */