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.

152 lines
4.1 KiB

  1. /*** EXP.C - expunge deleted files deleted with the rm program ****************
  2. *
  3. * Copyright (c) 1986-1990, Microsoft Corporation. All rights reserved.
  4. *
  5. * Purpose:
  6. * The three tools EXP, RM and UNDEL are used to delete files so
  7. * that they can be undeleted. This is done my renaming the file into
  8. * a hidden directory called DELETED.
  9. *
  10. * Notes:
  11. * Exp command line syntax:
  12. *
  13. * EXP [options] [path ...]
  14. *
  15. * where the [options] are :-
  16. *
  17. * /r Recursively expunge from path specified
  18. * /q Quiet mode; no extraneous messages
  19. * /help spawn Qh if possible, else issue a Usage message
  20. *
  21. * Revision History:
  22. * 08-Jan-1990 SB SLM version upgrading added; Add CopyRightYrs Macro
  23. * 03-Jan-1990 SB define QH_TOPIC_NOT_FOUND
  24. * 20-Dec-1989 SB Add check for return code of 3 for qh
  25. * 14-Dec-1989 LN Update Copyright to include 1990
  26. * 23-Oct-1989 LN Version no bumped to 1.01
  27. * 02-Oct-1989 LN Changed Version no to 1.00
  28. * 08-Aug-1989 BW Add Version number. Fix usage syntax. Update copyright.
  29. * 15-May-1989 WB Add /help
  30. * 06-Apr-1987 BW Add copyright notice to Usage().
  31. * 22-Jul-1986 DL Make test for flag case insensitive, add /q
  32. *
  33. ******************************************************************************/
  34. /* I N C L U D E Files */
  35. #include <stdio.h>
  36. #include <process.h>
  37. #include <ctype.h>
  38. #include <windows.h>
  39. #include <tools.h>
  40. #include <string.h>
  41. /* D E F I N E s */
  42. #define CopyRightYrs "1987-90"
  43. /* Need 2 steps, first to get correct values in and 2nd to paste them */
  44. /* paste() is hacked to allow LEADING ZEROES */
  45. #define paste(a, b, c) #a ".0" #b ".00" #c
  46. #define VERSION(major, minor, buildno) paste(major, minor, buildno)
  47. #define QH_TOPIC_NOT_FOUND 3
  48. /* G L O B A L s */
  49. flagType fRecurse = FALSE;
  50. FILE *pFile;
  51. char cd[MAX_PATH];
  52. /*
  53. * Forward Function Declarations...
  54. */
  55. void DoExp( char *, struct findType *, void *);
  56. void Usage( void );
  57. void
  58. DoExp(p, b, dummy)
  59. char *p;
  60. struct findType *b;
  61. void *dummy;
  62. {
  63. if (b == NULL ||
  64. (_strcmpi(b->fbuf.cFileName, "deleted") && TESTFLAG(b->fbuf.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY) &&
  65. strcmp(b->fbuf.cFileName, ".") && strcmp(b->fbuf.cFileName, ".."))) {
  66. fexpunge(p, pFile);
  67. if (fRecurse) {
  68. if (!fPathChr(*(strend(p)-1)))
  69. strcat(p, "\\");
  70. strcat(p, "*.*");
  71. forfile(p, FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM, DoExp, NULL);
  72. }
  73. }
  74. dummy;
  75. }
  76. void
  77. Usage()
  78. {
  79. printf(
  80. "Microsoft File Expunge Utility. Version %s\n"
  81. "Copyright (C) Microsoft Corp %s. All rights reserved.\n\n"
  82. "Usage: EXP [/help] [/rq] [{dir}*]\n",
  83. VERSION(rmj, rmm, rup), CopyRightYrs);
  84. exit( 1 );
  85. }
  86. __cdecl main(c, v)
  87. int c;
  88. char *v[];
  89. {
  90. char *p;
  91. intptr_t iRetCode;
  92. pFile = stdout;
  93. ConvertAppToOem( c, v );
  94. SHIFT(c,v);
  95. while( c && fSwitChr( *( p = *v ) ) ) {
  96. while (*++p) {
  97. switch (tolower(*p)) {
  98. case 'r':
  99. fRecurse = TRUE;
  100. break;
  101. case 'q':
  102. pFile = NULL;
  103. break;
  104. case 'h':
  105. if (!_strcmpi(p, "help")) {
  106. iRetCode = _spawnlp(P_WAIT, "qh.exe", "qh", "/u",
  107. "exp.exe", NULL);
  108. /* qh returns QH_TOPIC_NOT_FOUND and
  109. * -1 is returned when the spawn fails
  110. */
  111. if (iRetCode != QH_TOPIC_NOT_FOUND && iRetCode != -1)
  112. exit(0);
  113. }
  114. /*
  115. * else fall thru...
  116. */
  117. default:
  118. Usage();
  119. }
  120. }
  121. SHIFT(c,v);
  122. }
  123. if (!c) {
  124. rootpath(".", cd);
  125. DoExp(cd, NULL, NULL);
  126. }
  127. else
  128. while (c) {
  129. strcpy(cd, *v);
  130. DoExp(cd, NULL, NULL);
  131. SHIFT(c,v);
  132. }
  133. return( 0 );
  134. }