Leaked source code of windows server 2003
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.

1212 lines
30 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. Log.c
  5. Abstract:
  6. none.
  7. Author:
  8. Shishir Pardikar [Shishirp] 01-jan-1995
  9. Revision History:
  10. Joe Linn [JoeLinn] 23-jan-97 Ported for use on NT
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #pragma code_seg("PAGE")
  15. /********************************************************************/
  16. /** Copyright(c) Microsoft Corp., 1990-1991 **/
  17. /********************************************************************/
  18. // Hook Processing
  19. /******************************* Include Files ******************************/
  20. #ifndef CSC_RECORDMANAGER_WINNT
  21. #define WIN32_APIS
  22. #include "cshadow.h"
  23. #endif //ifndef CSC_RECORDMANAGER_WINNT
  24. #include <stdlib.h>
  25. #include <ctype.h>
  26. #include <string.h>
  27. // #include "error.h"
  28. #include "vxdwraps.h"
  29. #include "logdat.h"
  30. /******************************* defines/typedefs ***************************/
  31. #define MAX_SHADOW_LOG_ENTRY 512
  32. #define MAX_LOG_SIZE 100000
  33. #ifdef DEBUG
  34. #define SHADOW_TIMER_INTERVAL 30000
  35. #define STATS_FLUSH_COUNT 10
  36. #endif //DEBUG
  37. #define ENTERCRIT_LOG { if (!fLogInit) InitShadowLog();\
  38. if (fLogInit==-1) return; \
  39. Wait_Semaphore(semLog, BLOCK_SVC_INTS);}
  40. #define LEAVECRIT_LOG Signal_Semaphore(semLog);
  41. #ifdef CSC_RECORDMANAGER_WINNT
  42. //ntdef has already define TIME differently....fortuntely by macros....
  43. //so we undo this for the remainder of this file. the RIGHT solution is
  44. //to use a name like CSC_LOG_TIME.
  45. #undef _TIME
  46. #undef TIME
  47. #undef PTIME
  48. #endif //ifdef CSC_RECORDMANAGER_WINNT
  49. typedef struct tagTIME
  50. {
  51. WORD seconds;
  52. WORD minutes;
  53. WORD hours;
  54. WORD day;
  55. WORD month;
  56. WORD year;
  57. }
  58. TIME, FAR *LPTIME;
  59. #pragma intrinsic (memcmp, memcpy, memset, strcat, strcmp, strcpy, strlen)
  60. /******************************* Function Prototypes ************************/
  61. int vxd_vsprintf(char * lpOut, char * lpFmt, CONST VOID * lpParms);
  62. int PrintLog( LPSTR lpFmt, ...);
  63. void PrintNetTime(LONG ltime);
  64. void PrintNetShortTime(LONG ltime);
  65. void ExplodeTime( ULONG time, LPTIME lpTime );
  66. void LogPreamble(int, LPSTR, int, LPSTR);
  67. int WriteStats(BOOL);
  68. //need this for NT
  69. int WriteLog(void);
  70. /******************************** Static/Global data ************************/
  71. #ifdef CSC_RECORDMANAGER_WINNT
  72. #define UniToBCSPath(a,b,c,d)
  73. #define IFSMgr_DosToNetTime(a) ((0))
  74. #endif //ifdef CSC_RECORDMANAGER_WINNT
  75. AssertData;
  76. AssertError;
  77. char logpathbuff[MAX_PATH+1], rgchLogFileName[MAX_PATH];
  78. char chLogginBuffer[COPY_BUFF_SIZE];
  79. extern int fLog;
  80. extern LPSTR vlpszShadowDir;
  81. int fLogInit = FALSE;
  82. LPSTR lpLogBuff = chLogginBuffer;
  83. int cBuffSize = COPY_BUFF_SIZE;
  84. int indxCur = 0;
  85. VMM_SEMAPHORE semLog = 0L;
  86. #define FOURYEARS (3*365+366)
  87. ULONG ulMaxLogSize=0x00020000; // 128K log filesize by default
  88. #ifndef CSC_RECORDMANAGER_WINNT
  89. BOOL fPersistLog = TRUE;
  90. #else
  91. BOOL fPersistLog = FALSE;
  92. #endif
  93. #define DAYSECONDS (60L*60L*24L) // number of seconds in a day
  94. #define BIAS_70_TO_80 0x12CEA600L
  95. // days in a month
  96. int MonTab[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  97. /* structure stores intl settings for datetime format */
  98. char szCSCLog[] = "\\csc.log"; // keep this size below 8
  99. char szCRLF[] = "\r\n";
  100. char szBegin[] = "Begin";
  101. char szEnd[] = "End";
  102. char szContinue[] = "Continue";
  103. char szEndMarker[] = "END\n";
  104. ULONG ulMaxLogfileSize;
  105. DWORD dwDebugLogVector = DEBUG_LOG_BIT_RECORD|DEBUG_LOG_BIT_CSHADOW; // by default record manager logging is on
  106. #ifdef DEBUG
  107. ULONG cntVfnDelete=0, cntVfnCreateDir=0, cntVfnDeleteDir=0, cntVfnCheckDir=0, cntVfnGetAttrib=0;
  108. ULONG cntVfnSetAttrib=0, cntVfnFlush=0, cntVfnGetDiskInfo=0, cntVfnOpen=0;
  109. ULONG cntVfnRename=0, cntVfnSearchFirst=0, cntVfnSearchNext=0;
  110. ULONG cntVfnQuery=0, cntVfnDisconnect=0, cntVfnUncPipereq=0, cntVfnIoctl16Drive=0;
  111. ULONG cntVfnGetDiskParms=0, cntVfnFindOpen=0, cntVfnDasdIO=0;
  112. ULONG cntHfnFindNext=0, cntHfnFindClose=0;
  113. ULONG cntHfnRead=0, cntHfnWrite=0, cntHfnSeek=0, cntHfnClose=0, cntHfnCommit=0;
  114. ULONG cntHfnSetFileLocks=0, cntHfnRelFileLocks=0, cntHfnGetFileTimes=0, cntHfnSetFileTimes=0;
  115. ULONG cntHfnPipeRequest=0, cntHfnHandleInfo=0, cntHfnEnumHandle=0;
  116. ULONG cbReadLow=0, cbReadHigh=0, cbWriteLow=0, cbWriteHigh=0;
  117. ULONG cntVfnConnect=0;
  118. ULONG cntLastTotal=0;
  119. #endif //DEBUG
  120. /****************************************************************************/
  121. #ifndef CSC_RECORDMANAGER_WINNT
  122. #pragma VxD_LOCKED_CODE_SEG
  123. #endif //ifndef CSC_RECORDMANAGER_WINNT
  124. int InitShadowLog(
  125. )
  126. {
  127. int iRet = -1, lenT;
  128. if (fLog && !fLogInit && vlpszShadowDir)
  129. {
  130. if (!(semLog = Create_Semaphore(1)))
  131. goto bailout;
  132. strcpy(rgchLogFileName, (LPSTR)vlpszShadowDir);
  133. strcat(rgchLogFileName, szCSCLog);
  134. PrintLog(szCRLF);
  135. PrintNetTime(IFSMgr_Get_NetTime());
  136. PrintLog(szCRLF);
  137. fLogInit = 1;
  138. iRet = 0;
  139. }
  140. else
  141. {
  142. iRet = 0;
  143. }
  144. bailout:
  145. if (iRet)
  146. {
  147. if (semLog)
  148. Destroy_Semaphore(semLog);
  149. semLog = 0L;
  150. }
  151. return iRet;
  152. }
  153. int ShadowLog(
  154. LPSTR lpFmt,
  155. ...
  156. )
  157. {
  158. int pos, iRet = -1;
  159. if (!fLogInit)
  160. {
  161. InitShadowLog();
  162. }
  163. if (fLogInit)
  164. {
  165. if ((cBuffSize-indxCur+sizeof(szEndMarker)) < MAX_SHADOW_LOG_ENTRY)
  166. {
  167. iRet = WriteLog();
  168. #if 0
  169. PrintLog(szCRLF);
  170. PrintNetTime(IFSMgr_Get_NetTime());
  171. PrintLog(szCRLF);
  172. #endif
  173. }
  174. else
  175. {
  176. indxCur += vxd_vsprintf(lpLogBuff+indxCur, lpFmt, (LPSTR)&lpFmt+sizeof(lpFmt));
  177. // deliberately don't move the index pointer after writing the end marker
  178. // so when the next real log entry is written, the endmarker will be overwritten
  179. memcpy(lpLogBuff+indxCur, szEndMarker, sizeof(szEndMarker)-1);
  180. iRet = 0;
  181. }
  182. }
  183. else
  184. {
  185. iRet = 0;
  186. }
  187. return (iRet);
  188. }
  189. int TerminateShadowLog(
  190. )
  191. {
  192. int iRet = -1;
  193. if (fLogInit)
  194. {
  195. iRet = WriteLog();
  196. Destroy_Semaphore(semLog);
  197. semLog = 0L;
  198. fLogInit = 0;
  199. }
  200. else
  201. {
  202. iRet = 0;
  203. }
  204. return (iRet);
  205. }
  206. int FlushLog(
  207. )
  208. {
  209. int iRet = 0;
  210. if (!fLogInit)
  211. {
  212. InitShadowLog();
  213. }
  214. if (fLogInit==1)
  215. {
  216. Wait_Semaphore(semLog, BLOCK_SVC_INTS);
  217. iRet = WriteLog();
  218. Signal_Semaphore(semLog);
  219. }
  220. else
  221. {
  222. iRet = -1;
  223. }
  224. return (iRet);
  225. }
  226. #ifdef DEBUG
  227. int WriteLog(
  228. )
  229. {
  230. int iRet = -1;
  231. CSCHFILE hfShadowLog = CSCHFILE_NULL;
  232. ULONG pos;
  233. if (fLogInit && vlpszShadowDir)
  234. {
  235. if (fPersistLog)
  236. {
  237. if (!(hfShadowLog = CreateFileLocal(rgchLogFileName)))
  238. {
  239. KdPrint(("WriteLog: Couldn't open log file\r\n"));
  240. goto bailout;
  241. }
  242. if(GetFileSizeLocal(hfShadowLog, &pos))
  243. {
  244. KdPrint(("ShadowLog: log file error\r\n"));
  245. goto bailout;
  246. }
  247. if ((pos+indxCur) > ulMaxLogSize)
  248. {
  249. #if 0
  250. CloseFileLocal(hfShadowLog);
  251. DeleteFileLocal(lpszLogAlt, ATTRIB_DEL_ANY);
  252. RenameFileLocal(szLog, szLogAlt);
  253. if (!(hfShadowLog = CreateFileLocal(szLog)))
  254. {
  255. KdPrint(("WriteLog: Couldn't open shadow file\r\n"));
  256. goto bailout;
  257. }
  258. #endif
  259. pos=0; // wraparound the logfile
  260. }
  261. if (WriteFileLocal(hfShadowLog, pos, lpLogBuff, indxCur) != indxCur)
  262. {
  263. KdPrint(("ShadowLog: error writing the log at position %x \r\n", pos));
  264. goto bailout;
  265. }
  266. }
  267. iRet = 0;
  268. }
  269. bailout:
  270. if (hfShadowLog)
  271. {
  272. CloseFileLocal(hfShadowLog);
  273. }
  274. // no matter what happens, reset the index to 0
  275. indxCur = 0;
  276. return iRet;
  277. }
  278. #else
  279. int
  280. WriteLog(
  281. VOID
  282. )
  283. {
  284. // no matter what happens, reset the index to 0
  285. indxCur = 0;
  286. return 1;
  287. }
  288. #endif //DEBUG
  289. void EnterLogCrit(void)
  290. {
  291. ENTERCRIT_LOG;
  292. }
  293. void LeaveLogCrit(void)
  294. {
  295. LEAVECRIT_LOG;
  296. }
  297. /*
  298. * PrintNetTime
  299. *
  300. * Adds a time and a date to the end of a string.
  301. * Time is seconds since 1/1/70.
  302. *
  303. */
  304. void PrintNetTime(LONG ltime)
  305. {
  306. TIME tm;
  307. int d1, d2, d3;
  308. ExplodeTime( ltime, &tm );
  309. d1 = tm.month; d2 = tm.day; d3 = tm.year%100;
  310. PrintLog(szTimeDateFormat, tm.hours, tm.minutes, tm.seconds, d1, d2, d3);
  311. }
  312. /*
  313. * PrintNetTime
  314. *
  315. * Adds a time and a date to the end of a string.
  316. * Time is seconds since 1/1/70.
  317. *
  318. */
  319. void PrintNetShortTime( LONG ltime
  320. )
  321. {
  322. TIME tm;
  323. ExplodeTime( ltime, &tm );
  324. PrintLog(szTimeFormat, tm.hours, tm.minutes, tm.seconds);
  325. }
  326. int PrintLog(
  327. LPSTR lpFmt,
  328. ...
  329. )
  330. {
  331. indxCur += vxd_vsprintf(lpLogBuff+indxCur, lpFmt, (LPSTR)&lpFmt+sizeof(lpFmt));
  332. return(0);
  333. }
  334. VOID
  335. _cdecl
  336. DbgPrintLog(
  337. LPSTR lpFmt,
  338. ...
  339. )
  340. {
  341. ENTERCRIT_LOG;
  342. indxCur += vxd_vsprintf(lpLogBuff+indxCur, lpFmt, (LPSTR)&lpFmt+sizeof(lpFmt));
  343. LEAVECRIT_LOG;
  344. }
  345. void ExplodeTime( ULONG time, LPTIME lpTime )
  346. {
  347. ULONG date;
  348. WORD cLeaps;
  349. LONG days;
  350. WORD dpy;
  351. int i;
  352. time -= BIAS_70_TO_80;
  353. date = time / DAYSECONDS;
  354. time %= DAYSECONDS;
  355. lpTime->seconds = (WORD)(time % 60L);
  356. time /= 60L;
  357. lpTime->minutes = (WORD)(time % 60L);
  358. lpTime->hours = (WORD)(time / 60L);
  359. cLeaps = (WORD)(date / FOURYEARS); // # of full leap years
  360. days = date % FOURYEARS; // remaining days
  361. lpTime->year = cLeaps * 4 + 1980; // correct year
  362. MonTab[1] = 29; // set # days in Feb for leap years
  363. dpy = 366;
  364. days -= dpy;
  365. if (days >= 0) { // this is not a leap year
  366. dpy--;
  367. while (days >= 0) {
  368. lpTime->year++;
  369. days -= dpy;
  370. }
  371. MonTab[1] = 28; // set # days in Feb for non-leap years
  372. }
  373. days += dpy; // days = # days left in this year
  374. for (i=0; days >= MonTab[i]; i++)
  375. days -= MonTab[i];
  376. lpTime->month = (WORD)i + 1; // calculate 1-based month
  377. lpTime->day = (WORD)days + 1; // calculate 1-based day
  378. }
  379. void LogVfnDelete( PIOREQ pir
  380. )
  381. {
  382. TIME tm;
  383. #ifdef DEBUG
  384. ++cntVfnDelete;
  385. #endif //DEBUG
  386. if (fLog)
  387. {
  388. ENTERCRIT_LOG;
  389. memset(logpathbuff, 0, sizeof(logpathbuff));
  390. UniToBCSPath(logpathbuff, &pir->ir_ppath->pp_elements[0], MAX_PATH, BCS_OEM);
  391. logpathbuff[MAX_PATH]=0;
  392. LogPreamble(VFNLOG_DELETE, logpathbuff, pir->ir_error, szCR);
  393. LEAVECRIT_LOG;
  394. }
  395. }
  396. void LogVfnDir( PIOREQ pir
  397. )
  398. {
  399. #ifdef DEBUG
  400. if (pir->ir_flags == CREATE_DIR)
  401. ++cntVfnCreateDir;
  402. else if (pir->ir_flags == DELETE_DIR)
  403. ++cntVfnDeleteDir;
  404. else
  405. ++cntVfnCheckDir;
  406. #endif //DEBUG
  407. if (fLog)
  408. {
  409. ENTERCRIT_LOG;
  410. UniToBCSPath(logpathbuff, &pir->ir_ppath->pp_elements[0], MAX_PATH, BCS_OEM);
  411. logpathbuff[MAX_PATH]=0;
  412. if (pir->ir_flags==CREATE_DIR)
  413. LogPreamble(VFNLOG_CREATE_DIR, logpathbuff, pir->ir_error, szCR);
  414. else if (pir->ir_flags==DELETE_DIR)
  415. LogPreamble(VFNLOG_DELETE_DIR, logpathbuff, pir->ir_error, szCR);
  416. else if (pir->ir_flags==CHECK_DIR)
  417. LogPreamble(VFNLOG_CHECK_DIR, logpathbuff, pir->ir_error, szCR);
  418. else if (pir->ir_flags==QUERY83_DIR)
  419. {
  420. LogPreamble(VFNLOG_QUERY83_DIR, logpathbuff, pir->ir_error, NULL);
  421. UniToBCSPath(logpathbuff, &pir->ir_ppath2->pp_elements[0], MAX_PATH, BCS_OEM);
  422. ShadowLog(" %s\r\n", logpathbuff);
  423. }
  424. else
  425. {
  426. LogPreamble(VFNLOG_QUERYLONG_DIR, logpathbuff, pir->ir_error, NULL);
  427. UniToBCSPath(logpathbuff, &pir->ir_ppath2->pp_elements[0], MAX_PATH, BCS_OEM);
  428. ShadowLog(" %s\r\n", logpathbuff);
  429. }
  430. LEAVECRIT_LOG;
  431. }
  432. }
  433. void LogVfnFileAttrib( PIOREQ pir
  434. )
  435. {
  436. #ifdef DEBUG
  437. if (pir->ir_flags == GET_ATTRIBUTES)
  438. ++cntVfnGetAttrib;
  439. else
  440. ++cntVfnSetAttrib;
  441. #endif //DEBUG
  442. if (fLog)
  443. {
  444. ENTERCRIT_LOG;
  445. memset(logpathbuff, 0, sizeof(logpathbuff));
  446. UniToBCSPath(logpathbuff, &pir->ir_ppath->pp_elements[0], MAX_PATH, BCS_OEM);
  447. if (pir->ir_flags == GET_ATTRIBUTES)
  448. {
  449. LogPreamble(VFNLOG_GET_ATTRB, logpathbuff, pir->ir_error, NULL);
  450. ShadowLog(rgsLogCmd[VFNLOG_GET_ATTRB].lpFmt, pir->ir_attr);
  451. }
  452. else
  453. {
  454. LogPreamble(VFNLOG_SET_ATTRB, logpathbuff, pir->ir_error, NULL);
  455. ShadowLog(rgsLogCmd[VFNLOG_SET_ATTRB].lpFmt, pir->ir_attr);
  456. }
  457. LEAVECRIT_LOG;
  458. }
  459. }
  460. void LogVfnFlush( PIOREQ pir
  461. )
  462. {
  463. #ifdef DEBUG
  464. ++cntVfnFlush;
  465. #endif //DEBUG
  466. if (fLog)
  467. {
  468. ENTERCRIT_LOG;
  469. PpeToSvr(((PRESOURCE)(pir->ir_rh))->pp_elements, logpathbuff, sizeof(logpathbuff), BCS_OEM);
  470. LogPreamble(VFNLOG_FLUSH, logpathbuff, pir->ir_error, szCR);
  471. LEAVECRIT_LOG;
  472. }
  473. }
  474. void LogVfnGetDiskInfo( PIOREQ pir
  475. )
  476. {
  477. if (fLog)
  478. {
  479. ENTERCRIT_LOG;
  480. PpeToSvr(((PRESOURCE)(pir->ir_rh))->pp_elements, logpathbuff, sizeof(logpathbuff), BCS_OEM);
  481. LogPreamble(VFNLOG_GETDISKINFO, logpathbuff, pir->ir_error, szCR);
  482. LEAVECRIT_LOG;
  483. }
  484. }
  485. void LogVfnGetDiskParms( PIOREQ pir
  486. )
  487. {
  488. #ifdef DEBUG
  489. ++cntVfnGetDiskParms;
  490. #endif //DEBUG
  491. if (fLog)
  492. {
  493. ENTERCRIT_LOG;
  494. PpeToSvr(((PRESOURCE)(pir->ir_rh))->pp_elements, logpathbuff, sizeof(logpathbuff), BCS_OEM);
  495. LogPreamble(VFNLOG_GETDISKPARAMS, logpathbuff, pir->ir_error, szCR);
  496. LEAVECRIT_LOG;
  497. }
  498. }
  499. void LogVfnOpen( PIOREQ pir
  500. )
  501. {
  502. #ifdef DEBUG
  503. ++cntVfnOpen;
  504. #endif //DEBUG
  505. if (fLog)
  506. {
  507. ENTERCRIT_LOG;
  508. memset(logpathbuff, 0, sizeof(logpathbuff));
  509. UniToBCSPath(logpathbuff, &pir->ir_ppath->pp_elements[0], MAX_PATH, BCS_OEM);
  510. logpathbuff[MAX_PATH]=0;
  511. LogPreamble(VFNLOG_OPEN, logpathbuff, pir->ir_error, NULL);
  512. ShadowLog(rgsLogCmd[VFNLOG_OPEN].lpFmt,(ULONG)(pir->ir_flags), (ULONG)(pir->ir_options)
  513. , (ULONG)(pir->ir_attr), (ULONG)(pir->ir_size));
  514. PrintNetTime(IFSMgr_DosToNetTime(pir->ir_dostime));
  515. ShadowLog(szCR);
  516. LEAVECRIT_LOG;
  517. }
  518. }
  519. void LogVfnRename( PIOREQ pir
  520. )
  521. {
  522. #ifdef DEBUG
  523. ++cntVfnRename;
  524. #endif //DEBUG
  525. if (fLog)
  526. {
  527. ENTERCRIT_LOG;
  528. memset(logpathbuff, 0, sizeof(logpathbuff));
  529. UniToBCSPath(logpathbuff, &pir->ir_ppath->pp_elements[0], MAX_PATH, BCS_OEM);
  530. logpathbuff[MAX_PATH]=0;
  531. LogPreamble(VFNLOG_RENAME, logpathbuff, pir->ir_error, NULL);
  532. UniToBCSPath(logpathbuff, &pir->ir_ppath2->pp_elements[0], MAX_PATH, BCS_OEM);
  533. logpathbuff[MAX_PATH]=0;
  534. ShadowLog(rgsLogCmd[VFNLOG_RENAME].lpFmt, logpathbuff);
  535. LEAVECRIT_LOG;
  536. }
  537. }
  538. void LogVfnSearch( PIOREQ pir
  539. )
  540. {
  541. srch_entry *pse = (srch_entry *)(pir->ir_data);
  542. char szName[sizeof(pse->se_name)+1];
  543. #ifdef DEBUG
  544. if (pir->ir_flags == SEARCH_FIRST)
  545. ++cntVfnSearchFirst;
  546. else
  547. ++cntVfnSearchNext;
  548. #endif //DEBUG
  549. if (fLog)
  550. {
  551. ENTERCRIT_LOG;
  552. // BUGBUG expand this
  553. memset(szName, 0, sizeof(szName));
  554. memcpy(logpathbuff, pse->se_name, sizeof(pse->se_name));
  555. if (pir->ir_flags == SEARCH_FIRST)
  556. {
  557. memset(logpathbuff, 0, sizeof(logpathbuff));
  558. UniToBCSPath(logpathbuff, &pir->ir_ppath->pp_elements[0], MAX_PATH, BCS_OEM);
  559. LogPreamble(VFNLOG_SRCHFRST, logpathbuff, pir->ir_error, NULL);
  560. ShadowLog(rgsLogCmd[VFNLOG_SRCHFRST].lpFmt, pir->ir_attr, szName);
  561. }
  562. else
  563. {
  564. LogPreamble(VFNLOG_SRCHNEXT, szDummy, pir->ir_error, NULL);
  565. ShadowLog(rgsLogCmd[VFNLOG_SRCHNEXT].lpFmt, szName);
  566. }
  567. LEAVECRIT_LOG;
  568. }
  569. }
  570. void LogVfnQuery( PIOREQ pir,
  571. USHORT options
  572. )
  573. {
  574. #ifdef DEBUG
  575. ++cntVfnQuery;
  576. #endif //DEBUG
  577. if (fLog)
  578. {
  579. ENTERCRIT_LOG;
  580. memset(logpathbuff, 0, sizeof(logpathbuff));
  581. PpeToSvr(((PRESOURCE)(pir->ir_rh))->pp_elements, logpathbuff, sizeof(logpathbuff), BCS_OEM);
  582. if (options==0)
  583. {
  584. LogPreamble(VFNLOG_QUERY0, logpathbuff, pir->ir_error, szCR);
  585. }
  586. if (options==1)
  587. {
  588. LogPreamble(VFNLOG_QUERY0, logpathbuff, pir->ir_error, NULL);
  589. ShadowLog(rgsLogCmd[VFNLOG_QUERY1].lpFmt, (ULONG)(pir->ir_options));
  590. }
  591. else if (options==2)
  592. {
  593. LogPreamble(VFNLOG_QUERY0, logpathbuff, pir->ir_error, NULL);
  594. ShadowLog(rgsLogCmd[VFNLOG_QUERY2].lpFmt, (ULONG)(pir->ir_options), (ULONG)(pir->ir_length >> 16), (ULONG)(pir->ir_length & 0xffff));
  595. }
  596. LEAVECRIT_LOG;
  597. }
  598. }
  599. void LogVfnConnect( PIOREQ pir
  600. )
  601. {
  602. #ifdef DEBUG
  603. ++cntVfnConnect;
  604. #endif //DEBUG
  605. if (fLog)
  606. {
  607. ENTERCRIT_LOG;
  608. memset(logpathbuff, 0, sizeof(logpathbuff));
  609. UniToBCSPath(logpathbuff, &pir->ir_ppath->pp_elements[0], MAX_PATH, BCS_OEM);
  610. LogPreamble(VFNLOG_CONNECT, logpathbuff, pir->ir_error, NULL);
  611. ShadowLog(rgsLogCmd[VFNLOG_CONNECT].lpFmt, pir->ir_flags);
  612. LEAVECRIT_LOG;
  613. }
  614. }
  615. void LogVfnDisconnect( PIOREQ pir
  616. )
  617. {
  618. #ifdef DEBUG
  619. ++cntVfnDisconnect;
  620. #endif //DEBUG
  621. if (fLog)
  622. {
  623. ENTERCRIT_LOG;
  624. PpeToSvr(((PRESOURCE)(pir->ir_rh))->pp_elements, logpathbuff, sizeof(logpathbuff), BCS_OEM);
  625. LogPreamble(VFNLOG_DISCONNECT, logpathbuff, pir->ir_error, szCR);
  626. WriteLog();
  627. // TerminateShadowLog();
  628. LEAVECRIT_LOG;
  629. }
  630. }
  631. void LogVfnUncPipereq(
  632. PIOREQ pir
  633. )
  634. {
  635. #ifdef DEBUG
  636. ++cntVfnUncPipereq;
  637. #endif //DEBUG
  638. }
  639. void LogVfnIoctl16Drive (
  640. PIOREQ pir
  641. )
  642. {
  643. #ifdef DEBUG
  644. ++cntVfnIoctl16Drive ;
  645. #endif //DEBUG
  646. }
  647. void LogVfnDasdIO(
  648. PIOREQ pir
  649. )
  650. {
  651. #ifdef DEBUG
  652. ++cntVfnDasdIO;
  653. #endif //DEBUG
  654. }
  655. void LogVfnFindOpen( PIOREQ pir
  656. )
  657. {
  658. #ifdef DEBUG
  659. ++cntVfnFindOpen;
  660. #endif //DEBUG
  661. if (fLog)
  662. {
  663. ENTERCRIT_LOG;
  664. memset(logpathbuff, 0, sizeof(logpathbuff));
  665. UniToBCSPath(logpathbuff, &pir->ir_ppath->pp_elements[0], MAX_PATH, BCS_OEM);
  666. logpathbuff[MAX_PATH]=0;
  667. LogPreamble(VFNLOG_FINDOPEN, logpathbuff, pir->ir_error, NULL);
  668. if (!pir->ir_error)
  669. {
  670. memset(logpathbuff, 0, sizeof(logpathbuff));
  671. UniToBCS(logpathbuff, ((LPFIND32)(pir->ir_data))->cFileName, sizeof(((LPFIND32)(pir->ir_data))->cFileName)
  672. , sizeof(logpathbuff)-1, BCS_OEM);
  673. ShadowLog(rgsLogCmd[VFNLOG_FINDOPEN].lpFmt, pir->ir_attr, logpathbuff);
  674. }
  675. else
  676. {
  677. ShadowLog(szCR);
  678. }
  679. LEAVECRIT_LOG;
  680. }
  681. }
  682. void LogHfnFindNext( PIOREQ pir
  683. )
  684. {
  685. #ifdef DEBUG
  686. ++cntHfnFindNext;
  687. #endif //DEBUG
  688. if (fLog)
  689. {
  690. ENTERCRIT_LOG;
  691. LogPreamble(HFNLOG_FINDNEXT, szDummy, pir->ir_error, NULL);
  692. if (!pir->ir_error)
  693. {
  694. memset(logpathbuff, 0, sizeof(logpathbuff));
  695. UniToBCS(logpathbuff, ((LPFIND32)(pir->ir_data))->cFileName, sizeof(((LPFIND32)(pir->ir_data))->cFileName)
  696. , sizeof(logpathbuff)-1, BCS_OEM);
  697. ShadowLog(rgsLogCmd[HFNLOG_FINDNEXT].lpFmt, logpathbuff);
  698. }
  699. else
  700. {
  701. ShadowLog(szCR);
  702. }
  703. LEAVECRIT_LOG;
  704. }
  705. }
  706. void LogHfnFindClose( PIOREQ pir
  707. )
  708. {
  709. #ifdef DEBUG
  710. ++cntHfnFindClose;
  711. #endif //DEBUG
  712. if (fLog)
  713. {
  714. ENTERCRIT_LOG;
  715. LogPreamble(HFNLOG_FINDCLOSE, szDummy, pir->ir_error, szCR);
  716. LEAVECRIT_LOG;
  717. }
  718. }
  719. void LogHfnRead
  720. (
  721. PIOREQ pir
  722. )
  723. {
  724. #ifdef DEBUG
  725. ++cntHfnRead;
  726. #endif //DEBUG
  727. #ifdef MAYBE
  728. Incr64Bit(cbReadHigh, cbReadLow, (ULONG)(pir->ir_length));
  729. #endif //MAYBE
  730. if (fLog)
  731. {
  732. PFILEINFO pFileInfo = (PFILEINFO)(pir->ir_fh);
  733. ENTERCRIT_LOG;
  734. memset(logpathbuff, 0, sizeof(logpathbuff));
  735. UniToBCSPath(logpathbuff, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  736. LogPreamble(HFNLOG_READ, logpathbuff, pir->ir_error, NULL);
  737. ShadowLog(rgsLogCmd[HFNLOG_READ].lpFmt,
  738. (ULONG)(pir->ir_pos)-(ULONG)(pir->ir_length),
  739. (ULONG)(pir->ir_length));
  740. LEAVECRIT_LOG;
  741. }
  742. }
  743. void LogHfnWrite
  744. (
  745. PIOREQ pir
  746. )
  747. {
  748. #ifdef DEBUG
  749. ++cntHfnWrite;
  750. #endif //DEBUG
  751. #ifdef MAYBE
  752. Incr64Bit(cbWriteHigh, cbWriteLow, (ULONG)(pir->ir_length));
  753. #endif //MAYBE
  754. if (fLog)
  755. {
  756. PFILEINFO pFileInfo = (PFILEINFO)(pir->ir_fh);
  757. ENTERCRIT_LOG;
  758. memset(logpathbuff, 0, sizeof(logpathbuff));
  759. UniToBCSPath(logpathbuff, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  760. LogPreamble(HFNLOG_WRITE, logpathbuff, pir->ir_error, NULL);
  761. ShadowLog(rgsLogCmd[HFNLOG_WRITE].lpFmt,
  762. (ULONG)(pir->ir_pos)-(ULONG)(pir->ir_length),
  763. (ULONG)(pir->ir_length));
  764. LEAVECRIT_LOG;
  765. }
  766. }
  767. void LogHfnClose
  768. (
  769. PIOREQ pir,
  770. int closetype
  771. )
  772. {
  773. #ifdef DEBUG
  774. ++cntHfnClose;
  775. #endif //DEBUG
  776. if (fLog)
  777. {
  778. PFILEINFO pFileInfo = (PFILEINFO)(pir->ir_fh);
  779. ENTERCRIT_LOG;
  780. memset(logpathbuff, 0, sizeof(logpathbuff));
  781. UniToBCSPath(logpathbuff, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  782. LogPreamble(HFNLOG_CLOSE, logpathbuff, pir->ir_error, NULL);
  783. ShadowLog(rgsLogCmd[HFNLOG_CLOSE].lpFmt, closetype);
  784. LEAVECRIT_LOG;
  785. }
  786. }
  787. void LogHfnSeek
  788. (
  789. PIOREQ pir
  790. )
  791. {
  792. #ifdef DEBUG
  793. ++cntHfnSeek;
  794. #endif //DEBUG
  795. if (fLog)
  796. {
  797. PFILEINFO pFileInfo = (PFILEINFO)(pir->ir_fh);
  798. ENTERCRIT_LOG;
  799. memset(logpathbuff, 0, sizeof(logpathbuff));
  800. UniToBCSPath(logpathbuff, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  801. LogPreamble(HFNLOG_SEEK, logpathbuff, pir->ir_error, NULL);
  802. ShadowLog(rgsLogCmd[HFNLOG_SEEK].lpFmt, (ULONG)(pir->ir_pos), pir->ir_flags);
  803. LEAVECRIT_LOG;
  804. }
  805. }
  806. void LogHfnCommit
  807. (
  808. PIOREQ pir
  809. )
  810. {
  811. #ifdef DEBUG
  812. ++cntHfnCommit;
  813. #endif //DEBUG
  814. if (fLog)
  815. {
  816. PFILEINFO pFileInfo = (PFILEINFO)(pir->ir_fh);
  817. ENTERCRIT_LOG;
  818. memset(logpathbuff, 0, sizeof(logpathbuff));
  819. UniToBCSPath(logpathbuff, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  820. LogPreamble(HFNLOG_COMMIT, logpathbuff, pir->ir_error, szCR);
  821. LEAVECRIT_LOG;
  822. }
  823. }
  824. void LogHfnFileLocks
  825. (
  826. PIOREQ pir
  827. )
  828. {
  829. #ifdef DEBUG
  830. if (pir->ir_flags == LOCK_REGION)
  831. ++cntHfnSetFileLocks;
  832. else
  833. ++cntHfnRelFileLocks;
  834. #endif //DEBUG
  835. if (fLog)
  836. {
  837. PFILEINFO pFileInfo = (PFILEINFO)(pir->ir_fh);
  838. ENTERCRIT_LOG;
  839. memset(logpathbuff, 0, sizeof(logpathbuff));
  840. UniToBCSPath(logpathbuff, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  841. LogPreamble((pir->ir_flags==LOCK_REGION)?HFNLOG_FLOCK:HFNLOG_FUNLOCK, logpathbuff, pir->ir_error, NULL);
  842. if (!pir->ir_error)
  843. {
  844. ShadowLog(rgsLogCmd[HFNLOG_FLOCK].lpFmt
  845. , pir->ir_pos
  846. , pir->ir_locklen);
  847. }
  848. else
  849. {
  850. ShadowLog(szCR);
  851. }
  852. LEAVECRIT_LOG;
  853. }
  854. }
  855. void LogHfnFileTimes
  856. (
  857. PIOREQ pir
  858. )
  859. {
  860. #ifdef DEBUG
  861. if ((pir->ir_flags == GET_MODIFY_DATETIME)||(pir->ir_flags == GET_LAST_ACCESS_DATETIME))
  862. ++cntHfnGetFileTimes;
  863. else
  864. ++cntHfnSetFileTimes;
  865. #endif //DEBUG
  866. if (fLog)
  867. {
  868. PFILEINFO pFileInfo = (PFILEINFO)(pir->ir_fh);
  869. int indxFn = pir->ir_flags;
  870. if (indxFn==GET_MODIFY_DATETIME)
  871. {
  872. indxFn = HFNLOG_GET_TIME;
  873. }
  874. else if (indxFn==SET_MODIFY_DATETIME)
  875. {
  876. indxFn = HFNLOG_SET_TIME;
  877. }
  878. else if (indxFn==GET_LAST_ACCESS_DATETIME)
  879. {
  880. indxFn = HFNLOG_GET_LATIME;
  881. }
  882. else
  883. {
  884. indxFn = HFNLOG_SET_LATIME;
  885. }
  886. ENTERCRIT_LOG;
  887. memset(logpathbuff, 0, sizeof(logpathbuff));
  888. UniToBCSPath(logpathbuff, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  889. LogPreamble(indxFn, logpathbuff, pir->ir_error, NULL);
  890. if (!pir->ir_error)
  891. {
  892. PrintNetTime(IFSMgr_DosToNetTime(pir->ir_dostime));
  893. }
  894. ShadowLog(szCR);
  895. LEAVECRIT_LOG;
  896. }
  897. }
  898. void LogHfnPipeRequest
  899. (
  900. PIOREQ pir
  901. )
  902. {
  903. }
  904. void LogHfnHandleInfo(
  905. PIOREQ pir
  906. )
  907. {
  908. if (fLog)
  909. {
  910. PFILEINFO pFileInfo = (PFILEINFO)(pir->ir_fh);
  911. ENTERCRIT_LOG;
  912. memset(logpathbuff, 0, sizeof(logpathbuff));
  913. UniToBCSPath(logpathbuff, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  914. LogPreamble(HFNLOG_ENUMHANDLE, logpathbuff, pir->ir_error, NULL);
  915. ShadowLog(szCR);
  916. LEAVECRIT_LOG;
  917. }
  918. }
  919. void LogHfnEnumHandle(
  920. PIOREQ pir
  921. )
  922. {
  923. if (fLog)
  924. {
  925. PFILEINFO pFileInfo = (PFILEINFO)(pir->ir_fh);
  926. ENTERCRIT_LOG;
  927. memset(logpathbuff, 0, sizeof(logpathbuff));
  928. UniToBCSPath(logpathbuff, &(pFileInfo->pFdb->sppathRemoteFile.pp_elements[0]), MAX_PATH, BCS_OEM);
  929. LogPreamble(HFNLOG_ENUMHANDLE, logpathbuff, pir->ir_error, NULL);
  930. ShadowLog(rgsLogCmd[HFNLOG_ENUMHANDLE].lpFmt, pir->ir_flags);
  931. LEAVECRIT_LOG;
  932. }
  933. }
  934. void LogTiming(
  935. int verbosity,
  936. int stage
  937. )
  938. {
  939. if (fLog >= verbosity)
  940. {
  941. ShadowLog("%s: ", (stage==STAGE_BEGIN)
  942. ?szBegin:((stage==STAGE_END)?szEnd:szContinue));
  943. PrintNetShortTime(IFSMgr_Get_NetTime());
  944. ShadowLog(szCR);
  945. }
  946. }
  947. void LogPreamble( int indxFn,
  948. LPSTR lpSubject,
  949. int errCode,
  950. LPSTR lpPreTerm
  951. )
  952. {
  953. TIME tm;
  954. ExplodeTime(IFSMgr_Get_NetTime(), &tm);
  955. ShadowLog(szPreFmt
  956. , rgsLogCmd[indxFn].lpCmd
  957. , tm.hours, tm.minutes, tm.seconds
  958. , errCode
  959. , lpSubject);
  960. if (lpPreTerm)
  961. {
  962. ShadowLog(lpPreTerm);
  963. }
  964. }
  965. #ifdef MAYBE
  966. int Incr64Bit(
  967. ULONG uHigh,
  968. ULONG uLow,
  969. ULONG uIncr
  970. )
  971. {
  972. ULONG uTemp = uLow;
  973. uLow += uIncr;
  974. if (uLow < uTemp)
  975. ++uHigh;
  976. return 1;
  977. }
  978. #endif //MAYBE
  979. #ifdef DEBUG
  980. int WriteStats( BOOL fForce)
  981. {
  982. ULONG cntTotal;
  983. SHADOWSTORE sSS;
  984. cntTotal = cntVfnDelete+ cntVfnCreateDir+ cntVfnDeleteDir+ cntVfnCheckDir+ cntVfnGetAttrib+
  985. cntVfnSetAttrib+ cntVfnFlush+ cntVfnGetDiskInfo+ cntVfnOpen+
  986. cntVfnRename+ cntVfnSearchFirst+ cntVfnSearchNext+
  987. cntVfnQuery+ cntVfnDisconnect+ cntVfnUncPipereq+ cntVfnIoctl16Drive+
  988. cntVfnGetDiskParms+ cntVfnFindOpen+ cntVfnDasdIO+
  989. cntHfnFindNext+ cntHfnFindClose+
  990. cntHfnRead+ cntHfnWrite+ cntHfnSeek+ cntHfnClose+ cntHfnCommit+
  991. cntHfnSetFileLocks+ cntHfnRelFileLocks+ cntHfnGetFileTimes+ cntHfnSetFileTimes+
  992. cntHfnPipeRequest+ cntHfnHandleInfo+ cntHfnEnumHandle;
  993. ShadowLog("\r!***** Stats Begin *******\r");
  994. PrintNetTime(IFSMgr_Get_NetTime());
  995. ShadowLog("\r");
  996. if (!fForce && (cntTotal == cntLastTotal))
  997. {
  998. KdPrint(("No new network activity \r"));
  999. goto bailout;
  1000. }
  1001. cntLastTotal = cntTotal;
  1002. if (!cntTotal)
  1003. {
  1004. cntTotal = 1;
  1005. }
  1006. ShadowLog("Total remote operations=%d \r", cntTotal);
  1007. GetShadowSpaceInfo(&sSS);
  1008. ShadowLog("Space used=%d, Files=%d, Dirs=%d\r",
  1009. sSS.sCur.ulSize, sSS.sCur.ucntFiles, sSS.sCur.ucntDirs);
  1010. ShadowLog("\rFile Operations:\r");
  1011. ShadowLog("Open=%d%%, Close=%d%% \r",
  1012. (cntVfnOpen * 100/cntTotal),
  1013. (cntHfnClose * 100/cntTotal));
  1014. ShadowLog("Read=%d%%, Write=%d%%, Seek=%d%%\r",
  1015. (cntHfnRead * 100/cntTotal),
  1016. (cntHfnWrite * 100/cntTotal),
  1017. (cntHfnSeek * 100/cntTotal));
  1018. if (!cntHfnRead)
  1019. {
  1020. cntHfnRead = 1;
  1021. }
  1022. ShadowLog("ReadHits=%d%% of total reads\r", (cntReadHits*100)/cntHfnRead);
  1023. ShadowLog("GetFileTime=%d%% SetFileTime=%d%%\r",
  1024. (cntHfnGetFileTimes * 100/cntTotal),
  1025. (cntHfnSetFileTimes * 100/cntTotal));
  1026. ShadowLog("SetLock=%d%%, ReleaseLock=%d%% \r",
  1027. (cntHfnSetFileLocks * 100/cntTotal),
  1028. (cntHfnRelFileLocks * 100/cntTotal));
  1029. ShadowLog("Directory Operations: ");
  1030. ShadowLog("CreateDir=%d%%, DeleteDir=%d%%, CheckDir=%d%% \r",
  1031. (cntVfnCreateDir*100/cntTotal),
  1032. (cntVfnDeleteDir*100/cntTotal),
  1033. (cntVfnCheckDir*100/cntTotal));
  1034. ShadowLog("Find/Search Operations:\r");
  1035. ShadowLog("FindOpen=%d%%, FindNext=%d%%, FindClose=%d%% \r",
  1036. (cntVfnFindOpen * 100/cntTotal),
  1037. (cntHfnFindNext * 100/cntTotal),
  1038. (cntHfnFindClose * 100/cntTotal));
  1039. ShadowLog("SearchFirst=%d%%, SearchNext=%d%%\r",
  1040. (cntVfnSearchFirst * 100/cntTotal),
  1041. (cntVfnSearchNext * 100/cntTotal));
  1042. ShadowLog("Attributes: ");
  1043. ShadowLog("SetAttributes=%d%%, GetAttributes=%d%%\r",
  1044. (cntVfnSetAttrib * 100/cntTotal),
  1045. (cntVfnGetAttrib * 100/cntTotal));
  1046. ShadowLog("Name Mutations: ");
  1047. ShadowLog("Rename=%d%%, Delete=%d%% \r",
  1048. (cntVfnRename * 100/cntTotal),
  1049. (cntVfnDelete * 100/cntTotal));
  1050. bailout:
  1051. ShadowLog("\r***** Stats End ******* \r");
  1052. return 1;
  1053. }
  1054. void ShadowRestrictedEventCallback
  1055. (
  1056. )
  1057. {
  1058. FlushLog();
  1059. ENTERCRIT_LOG;
  1060. WriteStats(0); // Don't force him to write
  1061. LEAVECRIT_LOG;
  1062. FlushLog();
  1063. }
  1064. #endif //DEBUG
  1065.