ReactOS  0.4.15-dev-1623-g66cf1d2
autochk.c File Reference
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <ntddkbd.h>
#include <ndk/exfuncs.h>
#include <ndk/iofuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/psfuncs.h>
#include <ndk/rtlfuncs.h>
#include <fmifs/fmifs.h>
#include <fslib/vfatlib.h>
#include <fslib/vfatxlib.h>
#include <fslib/ntfslib.h>
#include <fslib/btrfslib.h>
#include <fslib/ext2lib.h>
#include <fslib/ffslib.h>
#include <fslib/reiserfslib.h>
#include <fslib/cdfslib.h>
#include <debug.h>
Include dependency graph for autochk.c:

Go to the source code of this file.

Classes

struct  _FILESYSTEM_CHKDSK
 

Macros

#define WIN32_NO_STATUS
 
#define NTOS_MODE_USER
 
#define NDEBUG
 

Typedefs

typedef struct _FILESYSTEM_CHKDSK FILESYSTEM_CHKDSK
 
typedef struct _FILESYSTEM_CHKDSKPFILESYSTEM_CHKDSK
 

Functions

static INT PrintString (char *fmt,...)
 
static VOID EraseLine (IN INT LineLength)
 
static NTSTATUS OpenKeyboard (OUT PHANDLE KeyboardHandle)
 
static NTSTATUS WaitForKeyboard (IN HANDLE KeyboardHandle, IN LONG TimeOut)
 
static NTSTATUS GetFileSystem (IN PUNICODE_STRING VolumePathU, IN OUT PWSTR FileSystemName, IN SIZE_T FileSystemNameSize)
 
static BOOLEAN NTAPI ChkdskCallback (IN CALLBACKCOMMAND Command, IN ULONG Modifier, IN PVOID Argument)
 
static NTSTATUS CheckVolume (IN PCWSTR VolumePath, IN LONG TimeOut, IN BOOLEAN CheckOnlyIfDirty)
 
static VOID QueryTimeout (IN OUT PLONG TimeOut)
 
INT __cdecl _main (IN INT argc, IN PCHAR argv[], IN PCHAR envp[], IN ULONG DebugFlag)
 

Variables

FILESYSTEM_CHKDSK FileSystems []
 
HANDLE KeyboardHandle = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 38 of file autochk.c.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 21 of file autochk.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 16 of file autochk.c.

Typedef Documentation

◆ FILESYSTEM_CHKDSK

◆ PFILESYSTEM_CHKDSK

Function Documentation

◆ _main()

INT __cdecl _main ( IN INT  argc,
IN PCHAR  argv[],
IN PCHAR  envp[],
IN ULONG  DebugFlag 
)

Definition at line 528 of file autochk.c.

533 {
535  LONG TimeOut;
536  ULONG i;
537  BOOLEAN CheckAllVolumes = FALSE;
538  BOOLEAN CheckOnlyIfDirty = TRUE;
540  PCHAR SkipDrives = NULL;
541  ANSI_STRING VolumePathA;
542  UNICODE_STRING VolumePathU;
543  WCHAR VolumePath[128] = L"";
544 
545  /*
546  * Parse the command-line: optional command switches,
547  * then the NT volume name (or drive letter) to be analysed.
548  * If "*" is passed this means that we check all the volumes.
549  */
550  if (argc <= 1)
551  {
552  /* Only one parameter (the program name), bail out */
553  return 1;
554  }
555  for (i = 1; i < argc; ++i)
556  {
557  if (argv[i][0] == '/' || argv[i][0] == '-')
558  {
559  DPRINT("Parameter %d: %s\n", i, argv[i]);
560  switch (toupper(argv[i][1]))
561  {
562  case 'K': /* List of drive letters to skip */
563  {
564  /* Check for the separator */
565  if (argv[i][2] != ':')
566  goto Default;
567 
568  SkipDrives = &argv[i][3];
569  break;
570  }
571 
572  case 'R': /* Repair the errors, implies /P */
573  case 'P': /* Check even if not dirty */
574  {
575  if (argv[i][2] != ANSI_NULL)
576  goto Default;
577 
578  CheckOnlyIfDirty = FALSE;
579  break;
580  }
581 
582  default: Default:
583  DPRINT1("Unknown switch %d: %s\n", i, argv[i]);
584  break;
585  }
586  }
587  else
588  {
589  DPRINT("Parameter %d - Volume specification: %s\n", i, argv[i]);
590  if (strcmp(argv[i], "*") == 0)
591  {
592  CheckAllVolumes = TRUE;
593  }
594  else
595  {
596  RtlInitEmptyUnicodeString(&VolumePathU,
597  VolumePath,
598  sizeof(VolumePath));
599  RtlInitAnsiString(&VolumePathA, argv[i]);
600  Status = RtlAnsiStringToUnicodeString(&VolumePathU,
601  &VolumePathA,
602  FALSE);
603  }
604 
605  /* Stop the parsing now */
606  break;
607  }
608  }
609 
610  /*
611  * FIXME: We should probably use here the mount manager to be
612  * able to check volumes which don't have a drive letter.
613  */
616  &DeviceMap.Query,
617  sizeof(DeviceMap.Query),
618  NULL);
619  if (!NT_SUCCESS(Status))
620  {
621  DPRINT1("NtQueryInformationProcess() failed, Status 0x%08lx\n", Status);
622  return 1;
623  }
624 
625  /* Filter out the skipped drives from the map */
626  if (SkipDrives && *SkipDrives)
627  {
628  DPRINT1("Skipping drives:");
629  while (*SkipDrives)
630  {
631 #if DBG
632  DbgPrint(" %c:", *SkipDrives);
633 #endif
634  /* Retrieve the index and filter the drive out */
635  i = toupper(*SkipDrives) - 'A';
636  if (0 <= i && i <= 'Z'-'A')
637  DeviceMap.Query.DriveMap &= ~(1 << i);
638 
639  /* Go to the next drive letter */
640  ++SkipDrives;
641  }
642  DbgPrint("\n");
643  }
644 
645  /* Query the timeout */
646  TimeOut = 3;
647  QueryTimeout(&TimeOut);
648 
649  /* Open the keyboard */
651  if (!NT_SUCCESS(Status))
652  {
653  DPRINT1("OpenKeyboard() failed, Status 0x%08lx\n", Status);
654  /* Ignore keyboard interaction */
655  }
656 
657  if (CheckAllVolumes)
658  {
659  /* Enumerate and check each of the available volumes */
660  for (i = 0; i <= 'Z'-'A'; i++)
661  {
662  if ((DeviceMap.Query.DriveMap & (1 << i)) &&
663  (DeviceMap.Query.DriveType[i] == DOSDEVICE_DRIVE_FIXED))
664  {
665  swprintf(VolumePath, L"\\??\\%c:", L'A' + i);
666  CheckVolume(VolumePath, TimeOut, CheckOnlyIfDirty);
667  }
668  }
669  }
670  else
671  {
672  /* Retrieve our index and analyse the volume */
673  if (wcslen(VolumePath) == 6 &&
674  VolumePath[0] == L'\\' &&
675  VolumePath[1] == L'?' &&
676  VolumePath[2] == L'?' &&
677  VolumePath[3] == L'\\' &&
678  VolumePath[5] == L':')
679  {
680  i = toupper(VolumePath[4]) - 'A';
681  if ((DeviceMap.Query.DriveMap & (1 << i)) &&
682  (DeviceMap.Query.DriveType[i] == DOSDEVICE_DRIVE_FIXED))
683  {
684  CheckVolume(VolumePath, TimeOut, CheckOnlyIfDirty);
685  }
686  }
687  else
688  {
689  /* Just perform the check on the specified volume */
690  // TODO: Check volume type using NtQueryVolumeInformationFile(FileFsDeviceInformation)
691  CheckVolume(VolumePath, TimeOut, CheckOnlyIfDirty);
692  }
693  }
694 
695  /* Close the keyboard */
696  if (KeyboardHandle)
698 
699  // PrintString("Done\r\n\r\n");
700  return 0;
701 }
signed char * PCHAR
Definition: retypes.h:7
static int argc
Definition: ServiceArgs.c:12
#define DbgPrint
Definition: loader.c:25
#define TRUE
Definition: types.h:120
HANDLE KeyboardHandle
Definition: autochk.c:64
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
#define swprintf
Definition: precomp.h:40
#define argv
Definition: mplay32.c:18
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define FALSE
Definition: types.h:117
#define ANSI_NULL
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
static VOID QueryTimeout(IN OUT PLONG TimeOut)
Definition: autochk.c:511
struct _PROCESS_DEVICEMAP_INFORMATION::@3968::@3970 Query
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
int toupper(int c)
Definition: utclib.c:881
#define DOSDEVICE_DRIVE_FIXED
Definition: obtypes.h:166
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
static const WCHAR L[]
Definition: oid.c:1250
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
static NTSTATUS OpenKeyboard(OUT PHANDLE KeyboardHandle)
Definition: autochk.c:130
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static NTSTATUS CheckVolume(IN PCWSTR VolumePath, IN LONG TimeOut, IN BOOLEAN CheckOnlyIfDirty)
Definition: autochk.c:395

◆ CheckVolume()

static NTSTATUS CheckVolume ( IN PCWSTR  VolumePath,
IN LONG  TimeOut,
IN BOOLEAN  CheckOnlyIfDirty 
)
static

Definition at line 395 of file autochk.c.

399 {
402  PCWSTR DisplayName;
403  UNICODE_STRING VolumePathU;
404  ULONG Count;
405  WCHAR FileSystem[128];
406 
407  RtlInitUnicodeString(&VolumePathU, VolumePath);
408 
409  /* Get a drive string for display purposes only */
410  if (wcslen(VolumePath) == 6 &&
411  VolumePath[0] == L'\\' &&
412  VolumePath[1] == L'?' &&
413  VolumePath[2] == L'?' &&
414  VolumePath[3] == L'\\' &&
415  VolumePath[5] == L':')
416  {
417  /* DOS drive */
418  DisplayName = &VolumePath[4];
419  }
420  else
421  {
422  DisplayName = VolumePath;
423  }
424 
425  DPRINT1("AUTOCHK: Checking %wZ\n", &VolumePathU);
426  PrintString("Verifying the file system on %S\r\n", DisplayName);
427 
428  /* Get the file system */
429  Status = GetFileSystem(&VolumePathU,
430  FileSystem,
431  sizeof(FileSystem));
432  if (!NT_SUCCESS(Status))
433  {
434  DPRINT1("GetFileSystem() failed, Status 0x%08lx\n", Status);
435  PrintString(" Unable to detect the file system of volume %S\r\n", DisplayName);
436  goto Quit;
437  }
438 
439  PrintString(" The file system type is %S.\r\n\r\n", FileSystem);
440 
441  /* Find a suitable file system provider */
442  for (Count = 0; Count < RTL_NUMBER_OF(FileSystems); ++Count)
443  {
444  if (wcscmp(FileSystem, FileSystems[Count].Name) == 0)
445  break;
446  }
448  {
449  DPRINT1("File system %S not supported\n", FileSystem);
450  PrintString(" Unable to verify the volume. The %S file system is not supported.\r\n", FileSystem);
452  goto Quit;
453  }
454 
455  /* Check whether the volume is dirty */
457  Success = FileSystems[Count].ChkdskFunc(&VolumePathU,
459  FALSE, // FixErrors
460  TRUE, // Verbose
461  TRUE, // CheckOnlyIfDirty
462  FALSE, // ScanDrive
463  NULL,
464  NULL,
465  NULL,
466  NULL,
467  (PULONG)&Status);
468 
469  /* Perform the check either when the volume is dirty or a check is forced */
470  if (Success && ((Status == STATUS_DISK_CORRUPT_ERROR) || !CheckOnlyIfDirty))
471  {
472  /* Let the user decide whether to repair */
474  {
475  PrintString("The file system on volume %S needs to be checked for problems.\r\n", DisplayName);
476  PrintString("You may cancel this check, but it is recommended that you continue.\r\n");
477  }
478  else
479  {
480  PrintString("A volume check has been scheduled.\r\n");
481  }
482 
484  {
485  PrintString("The system will now check the file system.\r\n\r\n");
487  Success = FileSystems[Count].ChkdskFunc(&VolumePathU,
489  TRUE, // FixErrors
490  TRUE, // Verbose
491  CheckOnlyIfDirty,
492  FALSE, // ScanDrive
493  NULL,
494  NULL,
495  NULL,
496  NULL,
497  (PULONG)&Status);
498  }
499  else
500  {
501  PrintString("The file system check has been skipped.\r\n");
502  }
503  }
504 
505 Quit:
506  PrintString("\r\n\r\n");
507  return Status;
508 }
const uint16_t * PCWSTR
Definition: typedefs.h:57
static NTSTATUS WaitForKeyboard(IN HANDLE KeyboardHandle, IN LONG TimeOut)
Definition: autochk.c:152
PWCHAR FileSystem
Definition: format.c:72
#define TRUE
Definition: types.h:120
HANDLE KeyboardHandle
Definition: autochk.c:64
LONG NTSTATUS
Definition: precomp.h:26
static INT PrintString(char *fmt,...)
Definition: autochk.c:73
static BOOLEAN NTAPI ChkdskCallback(IN CALLBACKCOMMAND Command, IN ULONG Modifier, IN PVOID Argument)
Definition: autochk.c:301
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
Status
Definition: gdiplustypes.h:24
PULIB_CHKDSK ChkdskFunc
Definition: autochk.c:46
int Count
Definition: noreturn.cpp:7
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
static NTSTATUS GetFileSystem(IN PUNICODE_STRING VolumePathU, IN OUT PWSTR FileSystemName, IN SIZE_T FileSystemNameSize)
Definition: autochk.c:232
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
FILESYSTEM_CHKDSK FileSystems[]
Definition: autochk.c:49
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define STATUS_DLL_NOT_FOUND
Definition: ntstatus.h:545
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by _main().

◆ ChkdskCallback()

static BOOLEAN NTAPI ChkdskCallback ( IN CALLBACKCOMMAND  Command,
IN ULONG  Modifier,
IN PVOID  Argument 
)
static

Definition at line 301 of file autochk.c.

305 {
306  PDWORD Percent;
309 
310  //
311  // We get other types of commands,
312  // but we don't have to pay attention to them
313  //
314  switch(Command)
315  {
316  case UNKNOWN2:
317  DPRINT("UNKNOWN2\n");
318  break;
319 
320  case UNKNOWN3:
321  DPRINT("UNKNOWN3\n");
322  break;
323 
324  case UNKNOWN4:
325  DPRINT("UNKNOWN4\n");
326  break;
327 
328  case UNKNOWN5:
329  DPRINT("UNKNOWN5\n");
330  break;
331 
332  case UNKNOWN9:
333  DPRINT("UNKNOWN9\n");
334  break;
335 
336  case UNKNOWNA:
337  DPRINT("UNKNOWNA\n");
338  break;
339 
340  case UNKNOWNC:
341  DPRINT("UNKNOWNC\n");
342  break;
343 
344  case UNKNOWND:
345  DPRINT("UNKNOWND\n");
346  break;
347 
348  case INSUFFICIENTRIGHTS:
349  DPRINT("INSUFFICIENTRIGHTS\n");
350  break;
351 
352  case FSNOTSUPPORTED:
353  DPRINT("FSNOTSUPPORTED\n");
354  break;
355 
356  case VOLUMEINUSE:
357  DPRINT("VOLUMEINUSE\n");
358  break;
359 
360  case STRUCTUREPROGRESS:
361  DPRINT("STRUCTUREPROGRESS\n");
362  break;
363 
364  case DONEWITHSTRUCTURE:
365  DPRINT("DONEWITHSTRUCTURE\n");
366  break;
367 
368  case CLUSTERSIZETOOSMALL:
369  DPRINT("CLUSTERSIZETOOSMALL\n");
370  break;
371 
372  case PROGRESS:
373  Percent = (PDWORD) Argument;
374  PrintString("%d percent completed.\r", *Percent);
375  break;
376 
377  case OUTPUT:
378  Output = (PTEXTOUTPUT) Argument;
379  PrintString("%s", Output->Output);
380  break;
381 
382  case DONE:
383  Status = (PBOOLEAN)Argument;
384  if (*Status == FALSE)
385  {
386  PrintString("The file system check was unable to complete successfully.\r\n\r\n");
387  // Error = TRUE;
388  }
389  break;
390  }
391  return TRUE;
392 }
Definition: fmifs.h:71
Definition: fmifs.h:72
Definition: fmifs.h:70
#define TRUE
Definition: types.h:120
static INT PrintString(char *fmt,...)
Definition: autochk.c:73
Definition: fmifs.h:68
Definition: fmifs.h:78
Definition: fmifs.h:73
Definition: shell.h:41
struct TEXTOUTPUT * PTEXTOUTPUT
Definition: fmifs.h:77
Definition: fmifs.h:80
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
char * PBOOLEAN
Definition: retypes.h:11
Definition: arc.h:85
DWORD * PDWORD
Definition: pedump.c:68
Definition: fmifs.h:81
#define DONE
Definition: rnr20lib.h:14
Definition: fmifs.h:82

Referenced by CheckVolume().

◆ EraseLine()

static VOID EraseLine ( IN INT  LineLength)
static

Definition at line 96 of file autochk.c.

98 {
99  INT Len;
101  WCHAR buffer[512];
102 
103  if (LineLength <= 0)
104  return;
105 
106  /* Go to the beginning of the line */
109 
110  /* Fill the buffer chunk with spaces */
111  Len = min(LineLength, ARRAYSIZE(buffer));
112  while (Len > 0) buffer[--Len] = L' ';
113 
114  RtlInitEmptyUnicodeString(&UnicodeString, buffer, sizeof(buffer));
115  while (LineLength > 0)
116  {
117  /* Display the buffer */
118  Len = min(LineLength, ARRAYSIZE(buffer));
119  LineLength -= Len;
120  UnicodeString.Length = Len * sizeof(WCHAR);
122  }
123 
124  /* Go to the beginning of the line */
127 }
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
GLuint buffer
Definition: glext.h:5915
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PCUNICODE_STRING UnicodeString
Definition: wdfstring.h:64
int32_t INT
Definition: typedefs.h:58
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define Len
Definition: deflate.h:82
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI NtDisplayString(PUNICODE_STRING String)
#define min(a, b)
Definition: monoChain.cc:55
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

Referenced by WaitForKeyboard().

◆ GetFileSystem()

static NTSTATUS GetFileSystem ( IN PUNICODE_STRING  VolumePathU,
IN OUT PWSTR  FileSystemName,
IN SIZE_T  FileSystemNameSize 
)
static

Definition at line 232 of file autochk.c.

236 {
241  PFILE_FS_ATTRIBUTE_INFORMATION FileFsAttribute;
243 
244  FileFsAttribute = (PFILE_FS_ATTRIBUTE_INFORMATION)Buffer;
245 
247  VolumePathU,
249  NULL,
250  NULL);
251 
255  &IoStatusBlock,
256  NULL,
257  0,
259  FILE_OPEN,
260  0,
261  NULL,
262  0);
263  if (!NT_SUCCESS(Status))
264  {
265  DPRINT1("Could not open volume '%wZ' to obtain its file system, Status 0x%08lx\n",
266  VolumePathU, Status);
267  return Status;
268  }
269 
271  &IoStatusBlock,
272  FileFsAttribute,
273  sizeof(Buffer),
276 
277  if (!NT_SUCCESS(Status))
278  {
279  DPRINT1("NtQueryVolumeInformationFile() failed, Status 0x%08lx\n", Status);
280  return Status;
281  }
282 
283  if (FileSystemNameSize >= FileFsAttribute->FileSystemNameLength + sizeof(WCHAR))
284  {
285  RtlCopyMemory(FileSystemName,
286  FileFsAttribute->FileSystemName,
287  FileFsAttribute->FileSystemNameLength);
288  FileSystemName[FileFsAttribute->FileSystemNameLength / sizeof(WCHAR)] = UNICODE_NULL;
289  }
290  else
291  {
293  }
294 
295  return STATUS_SUCCESS;
296 }
#define FILE_GENERIC_READ
Definition: nt_native.h:653
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
#define FILE_SHARE_READ
Definition: compat.h:136
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
HANDLE FileHandle
Definition: stats.c:38
#define UNICODE_NULL
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:34
struct _FILE_FS_ATTRIBUTE_INFORMATION * PFILE_FS_ATTRIBUTE_INFORMATION
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
unsigned char UCHAR
Definition: xmlstorage.h:181
#define FILE_OPEN
Definition: from_kernel.h:54
NTSTATUS NTAPI NtQueryVolumeInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation, ULONG Length, FS_INFORMATION_CLASS FsInformationClass)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by CheckVolume().

◆ OpenKeyboard()

static NTSTATUS OpenKeyboard ( OUT PHANDLE  KeyboardHandle)
static

Definition at line 130 of file autochk.c.

132 {
135  UNICODE_STRING KeyboardName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardClass0");
136 
137  /* Just open the class driver */
139  &KeyboardName,
140  0,
141  NULL,
142  NULL);
143  return NtOpenFile(KeyboardHandle,
146  &IoStatusBlock,
147  FILE_OPEN,
148  0);
149 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
HANDLE KeyboardHandle
Definition: autochk.c:64
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
static const WCHAR L[]
Definition: oid.c:1250
#define FILE_OPEN
Definition: from_kernel.h:54
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by _main().

◆ PrintString()

static INT PrintString ( char fmt,
  ... 
)
static

Definition at line 73 of file autochk.c.

74 {
75  INT Len;
76  char buffer[512];
77  va_list ap;
80 
81  va_start(ap, fmt);
82  Len = vsprintf(buffer, fmt, ap);
83  va_end(ap);
84 
87  &AnsiString,
88  TRUE);
91 
92  return Len;
93 }
#define TRUE
Definition: types.h:120
GLuint buffer
Definition: glext.h:5915
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PCUNICODE_STRING UnicodeString
Definition: wdfstring.h:64
int32_t INT
Definition: typedefs.h:58
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
#define Len
Definition: deflate.h:82
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
va_start(ap, x)
NTSTATUS NTAPI NtDisplayString(PUNICODE_STRING String)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
Definition: dsound.c:943

Referenced by CheckVolume(), ChkdskCallback(), and WaitForKeyboard().

◆ QueryTimeout()

static VOID QueryTimeout ( IN OUT PLONG  TimeOut)
static

Definition at line 511 of file autochk.c.

513 {
515 
518  QueryTable[0].Name = L"AutoChkTimeOut";
519  QueryTable[0].EntryContext = TimeOut;
520 
522  /* See: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/autochk */
523  *TimeOut = min(max(*TimeOut, 0), 259200);
524 }
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4142
#define max(a, b)
Definition: svc.c:63
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
static const WCHAR L[]
Definition: oid.c:1250
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144

Referenced by _main().

◆ WaitForKeyboard()

static NTSTATUS WaitForKeyboard ( IN HANDLE  KeyboardHandle,
IN LONG  TimeOut 
)
static

Definition at line 152 of file autochk.c.

155 {
159  KEYBOARD_INPUT_DATA InputData;
160  INT Len = 0;
161 
162  /* Skip the wait if there is no timeout */
163  if (TimeOut <= 0)
164  return STATUS_TIMEOUT;
165 
166  /* Attempt to read a down key-press from the keyboard */
167  do
168  {
169  Offset.QuadPart = 0;
171  NULL,
172  NULL,
173  NULL,
174  &IoStatusBlock,
175  &InputData,
176  sizeof(KEYBOARD_INPUT_DATA),
177  &Offset,
178  NULL);
179  if (!NT_SUCCESS(Status))
180  {
181  /* Something failed, bail out */
182  return Status;
183  }
184  if ((Status != STATUS_PENDING) && !(InputData.Flags & KEY_BREAK))
185  {
186  /* We have a down key-press, return */
187  return Status;
188  }
189  } while (Status != STATUS_PENDING);
190 
191  /* Perform the countdown of TimeOut seconds */
193  while (TimeOut > 0)
194  {
195  /*
196  * Display the countdown string.
197  * Note that we only do a carriage return to go back to the
198  * beginning of the line to possibly erase it. Note also that
199  * we display a trailing space to erase any last character
200  * when the string length decreases.
201  */
202  Len = PrintString("Press any key within %d second(s) to cancel and resume startup. \r", TimeOut);
203 
204  /* Decrease the countdown */
205  --TimeOut;
206 
207  /* Wait one second for a key press */
208  Timeout.QuadPart = -10000000;
210  if (Status != STATUS_TIMEOUT)
211  break;
212  }
213 
214  /* Erase the countdown string */
215  EraseLine(Len);
216 
217  if (Status == STATUS_TIMEOUT)
218  {
219  /* The user did not press any key, cancel the read */
221  }
222  else
223  {
224  /* Otherwise, return some status */
226  }
227 
228  return Status;
229 }
HANDLE KeyboardHandle
Definition: autochk.c:64
LONG NTSTATUS
Definition: precomp.h:26
static INT PrintString(char *fmt,...)
Definition: autochk.c:73
#define KEY_BREAK
Definition: ntddkbd.h:71
int32_t INT
Definition: typedefs.h:58
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
static VOID EraseLine(IN INT LineLength)
Definition: autochk.c:96
#define Len
Definition: deflate.h:82
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
static ULONG Timeout
Definition: ping.c:61
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI NtCancelIoFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock)
Definition: file.c:4018
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by CheckVolume().

Variable Documentation

◆ FileSystems

FILESYSTEM_CHKDSK FileSystems[]
Initial value:
=
{
{ L"FAT", VfatChkdsk },
{ L"FAT32", VfatChkdsk },
{ L"FATX" , VfatxChkdsk },
{ L"NTFS", NtfsChkdsk },
{ L"BTRFS", BtrfsChkdsk },
{ L"EXT2", Ext2Chkdsk },
{ L"EXT3", Ext2Chkdsk },
{ L"EXT4", Ext2Chkdsk },
{ L"FFS", FfsChkdsk },
{ L"RFSD", ReiserfsChkdsk },
{ L"CDFS", CdfsChkdsk },
}
BOOLEAN NTAPI Ext2Chkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: Mke2fs.c:1007
BOOLEAN NTAPI FfsChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: ffslib.c:33
BOOLEAN NTAPI NtfsChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: ntfslib.c:33
BOOLEAN NTAPI VfatxChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: vfatxlib.c:162
BOOLEAN NTAPI BtrfsChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
static const WCHAR L[]
Definition: oid.c:1250
BOOLEAN NTAPI VfatChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: vfatlib.c:374
BOOLEAN NTAPI ReiserfsChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: reiserfslib.c:33
BOOLEAN NTAPI CdfsChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: cdfslib.c:32

Definition at line 49 of file autochk.c.

Referenced by CheckVolume(), and GetFileSystemByName().

◆ KeyboardHandle

HANDLE KeyboardHandle = NULL

Definition at line 64 of file autochk.c.

Referenced by _main(), CheckVolume(), OpenKeyboard(), and WaitForKeyboard().