ReactOS  0.4.14-dev-55-g2da92ac
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/ntfslib.h>
#include <fslib/ext2lib.h>
#include <fslib/btrfslib.h>
#include <fslib/reiserfslib.h>
#include <fslib/ffslib.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 [10]
 
HANDLE KeyboardHandle = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 37 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 513 of file autochk.c.

518 {
520  LONG TimeOut;
521  ULONG i;
522  BOOLEAN CheckAllVolumes = FALSE;
523  BOOLEAN CheckOnlyIfDirty = TRUE;
525  PCHAR SkipDrives = NULL;
526  ANSI_STRING VolumePathA;
527  UNICODE_STRING VolumePathU;
528  WCHAR VolumePath[128] = L"";
529 
530  /*
531  * Parse the command-line: optional command switches,
532  * then the NT volume name (or drive letter) to be analysed.
533  * If "*" is passed this means that we check all the volumes.
534  */
535  if (argc <= 1)
536  {
537  /* Only one parameter (the program name), bail out */
538  return 1;
539  }
540  for (i = 1; i < argc; ++i)
541  {
542  if (argv[i][0] == '/' || argv[i][0] == '-')
543  {
544  DPRINT("Parameter %d: %s\n", i, argv[i]);
545  switch (toupper(argv[i][1]))
546  {
547  case 'K': /* List of drive letters to skip */
548  {
549  /* Check for the separator */
550  if (argv[i][2] != ':')
551  goto Default;
552 
553  SkipDrives = &argv[i][3];
554  break;
555  }
556 
557  case 'R': /* Repair the errors, implies /P */
558  case 'P': /* Check even if not dirty */
559  {
560  if (argv[i][2] != ANSI_NULL)
561  goto Default;
562 
563  CheckOnlyIfDirty = FALSE;
564  break;
565  }
566 
567  default: Default:
568  DPRINT1("Unknown switch %d: %s\n", i, argv[i]);
569  break;
570  }
571  }
572  else
573  {
574  DPRINT("Parameter %d - Volume specification: %s\n", i, argv[i]);
575  if (strcmp(argv[i], "*") == 0)
576  {
577  CheckAllVolumes = TRUE;
578  }
579  else
580  {
581  RtlInitEmptyUnicodeString(&VolumePathU,
582  VolumePath,
583  sizeof(VolumePath));
584  RtlInitAnsiString(&VolumePathA, argv[i]);
585  Status = RtlAnsiStringToUnicodeString(&VolumePathU,
586  &VolumePathA,
587  FALSE);
588  }
589 
590  /* Stop the parsing now */
591  break;
592  }
593  }
594 
595  /*
596  * FIXME: We should probably use here the mount manager to be
597  * able to check volumes which don't have a drive letter.
598  */
601  &DeviceMap.Query,
602  sizeof(DeviceMap.Query),
603  NULL);
604  if (!NT_SUCCESS(Status))
605  {
606  DPRINT1("NtQueryInformationProcess() failed, Status 0x%08lx\n", Status);
607  return 1;
608  }
609 
610  /* Filter out the skipped drives from the map */
611  if (SkipDrives && *SkipDrives)
612  {
613  DPRINT1("Skipping drives:");
614  while (*SkipDrives)
615  {
616 #if DBG
617  DbgPrint(" %c:", *SkipDrives);
618 #endif
619  /* Retrieve the index and filter the drive out */
620  i = toupper(*SkipDrives) - 'A';
621  if (0 <= i && i <= 'Z'-'A')
622  DeviceMap.Query.DriveMap &= ~(1 << i);
623 
624  /* Go to the next drive letter */
625  ++SkipDrives;
626  }
627  DbgPrint("\n");
628  }
629 
630  /* Query the timeout */
631  TimeOut = 3;
632  QueryTimeout(&TimeOut);
633 
634  /* Open the keyboard */
636  if (!NT_SUCCESS(Status))
637  {
638  DPRINT1("OpenKeyboard() failed, Status 0x%08lx\n", Status);
639  /* Ignore keyboard interaction */
640  }
641 
642  if (CheckAllVolumes)
643  {
644  /* Enumerate and check each of the available volumes */
645  for (i = 0; i <= 'Z'-'A'; i++)
646  {
647  if ((DeviceMap.Query.DriveMap & (1 << i)) &&
648  (DeviceMap.Query.DriveType[i] == DOSDEVICE_DRIVE_FIXED))
649  {
650  swprintf(VolumePath, L"\\??\\%c:", L'A' + i);
651  CheckVolume(VolumePath, TimeOut, CheckOnlyIfDirty);
652  }
653  }
654  }
655  else
656  {
657  /* Retrieve our index and analyse the volume */
658  if (wcslen(VolumePath) == 6 &&
659  VolumePath[0] == L'\\' &&
660  VolumePath[1] == L'?' &&
661  VolumePath[2] == L'?' &&
662  VolumePath[3] == L'\\' &&
663  VolumePath[5] == L':')
664  {
665  i = toupper(VolumePath[4]) - 'A';
666  if ((DeviceMap.Query.DriveMap & (1 << i)) &&
667  (DeviceMap.Query.DriveType[i] == DOSDEVICE_DRIVE_FIXED))
668  {
669  CheckVolume(VolumePath, TimeOut, CheckOnlyIfDirty);
670  }
671  }
672  else
673  {
674  /* Just perform the check on the specified volume */
675  // TODO: Check volume type using NtQueryVolumeInformationFile(FileFsDeviceInformation)
676  CheckVolume(VolumePath, TimeOut, CheckOnlyIfDirty);
677  }
678  }
679 
680  /* Close the keyboard */
681  if (KeyboardHandle)
683 
684  // PrintString("Done\r\n\r\n");
685  return 0;
686 }
signed char * PCHAR
Definition: retypes.h:7
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
HANDLE KeyboardHandle
Definition: autochk.c:62
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 argv
Definition: mplay32.c:18
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
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
#define ANSI_NULL
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static VOID QueryTimeout(IN OUT PLONG TimeOut)
Definition: autochk.c:496
#define NtCurrentProcess()
Definition: nt_native.h:1657
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
#define swprintf(buf, format,...)
Definition: sprintf.c:56
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
static NTSTATUS OpenKeyboard(OUT PHANDLE KeyboardHandle)
Definition: autochk.c:128
#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:393
struct _PROCESS_DEVICEMAP_INFORMATION::@3781::@3783 Query

◆ CheckVolume()

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

Definition at line 393 of file autochk.c.

397 {
399  PCWSTR DisplayName;
400  UNICODE_STRING VolumePathU;
401  ULONG Count;
402  WCHAR FileSystem[128];
403 
404  RtlInitUnicodeString(&VolumePathU, VolumePath);
405 
406  /* Get a drive string for display purposes only */
407  if (wcslen(VolumePath) == 6 &&
408  VolumePath[0] == L'\\' &&
409  VolumePath[1] == L'?' &&
410  VolumePath[2] == L'?' &&
411  VolumePath[3] == L'\\' &&
412  VolumePath[5] == L':')
413  {
414  /* DOS drive */
415  DisplayName = &VolumePath[4];
416  }
417  else
418  {
419  DisplayName = VolumePath;
420  }
421 
422  DPRINT1("AUTOCHK: Checking %wZ\n", &VolumePathU);
423  PrintString("Verifying the file system on %S\r\n", DisplayName);
424 
425  /* Get the file system */
426  Status = GetFileSystem(&VolumePathU,
427  FileSystem,
428  sizeof(FileSystem));
429  if (!NT_SUCCESS(Status))
430  {
431  DPRINT1("GetFileSystem() failed, Status 0x%08lx\n", Status);
432  PrintString(" Unable to detect the file system of volume %S\r\n", DisplayName);
433  goto Quit;
434  }
435 
436  PrintString(" The file system type is %S.\r\n\r\n", FileSystem);
437 
438  /* Find a suitable file system provider */
439  for (Count = 0; Count < RTL_NUMBER_OF(FileSystems); ++Count)
440  {
441  if (wcscmp(FileSystem, FileSystems[Count].Name) == 0)
442  break;
443  }
445  {
446  DPRINT1("File system %S not supported\n", FileSystem);
447  PrintString(" Unable to verify the volume. The %S file system is not supported.\r\n", FileSystem);
449  goto Quit;
450  }
451 
452  /* Check whether the volume is dirty */
453  Status = FileSystems[Count].ChkdskFunc(&VolumePathU,
454  FALSE, // FixErrors
455  TRUE, // Verbose
456  TRUE, // CheckOnlyIfDirty
457  FALSE, // ScanDrive
459 
460  /* Perform the check either when the volume is dirty or a check is forced */
461  if ((Status == STATUS_DISK_CORRUPT_ERROR) || !CheckOnlyIfDirty)
462  {
463  /* Let the user decide whether to repair */
465  {
466  PrintString("The file system on volume %S needs to be checked for problems.\r\n", DisplayName);
467  PrintString("You may cancel this check, but it is recommended that you continue.\r\n");
468  }
469  else
470  {
471  PrintString("A volume check has been scheduled.\r\n");
472  }
473 
475  {
476  PrintString("The system will now check the file system.\r\n\r\n");
477  Status = FileSystems[Count].ChkdskFunc(&VolumePathU,
478  TRUE, // FixErrors
479  TRUE, // Verbose
480  CheckOnlyIfDirty,
481  FALSE, // ScanDrive
483  }
484  else
485  {
486  PrintString("The file system check has been skipped.\r\n");
487  }
488  }
489 
490 Quit:
491  PrintString("\r\n\r\n");
492  return Status;
493 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
static NTSTATUS WaitForKeyboard(IN HANDLE KeyboardHandle, IN LONG TimeOut)
Definition: autochk.c:150
CHKDSKEX ChkdskFunc
Definition: autochk.c:45
#define TRUE
Definition: types.h:120
PWCHAR FileSystem
Definition: format.c:72
HANDLE KeyboardHandle
Definition: autochk.c:62
LONG NTSTATUS
Definition: precomp.h:26
static INT PrintString(char *fmt,...)
Definition: autochk.c:71
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
static BOOLEAN NTAPI ChkdskCallback(IN CALLBACKCOMMAND Command, IN ULONG Modifier, IN PVOID Argument)
Definition: autochk.c:299
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FILESYSTEM_CHKDSK FileSystems[10]
Definition: autochk.c:48
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
static NTSTATUS GetFileSystem(IN PUNICODE_STRING VolumePathU, IN OUT PWSTR FileSystemName, IN SIZE_T FileSystemNameSize)
Definition: autochk.c:230
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define STATUS_DLL_NOT_FOUND
Definition: ntstatus.h:531
#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)
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 299 of file autochk.c.

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

96 {
97  INT Len;
99  WCHAR buffer[512];
100 
101  if (LineLength <= 0)
102  return;
103 
104  /* Go to the beginning of the line */
107 
108  /* Fill the buffer chunk with spaces */
109  Len = min(LineLength, ARRAYSIZE(buffer));
110  while (Len > 0) buffer[--Len] = L' ';
111 
112  RtlInitEmptyUnicodeString(&UnicodeString, buffer, sizeof(buffer));
113  while (LineLength > 0)
114  {
115  /* Display the buffer */
116  Len = min(LineLength, ARRAYSIZE(buffer));
117  LineLength -= Len;
118  UnicodeString.Length = Len * sizeof(WCHAR);
120  }
121 
122  /* Go to the beginning of the line */
125 }
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1980
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
GLuint buffer
Definition: glext.h:5915
int32_t INT
Definition: typedefs.h:56
__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 230 of file autochk.c.

234 {
239  PFILE_FS_ATTRIBUTE_INFORMATION FileFsAttribute;
241 
242  FileFsAttribute = (PFILE_FS_ATTRIBUTE_INFORMATION)Buffer;
243 
245  VolumePathU,
247  NULL,
248  NULL);
249 
253  &IoStatusBlock,
254  NULL,
255  0,
257  FILE_OPEN,
258  0,
259  NULL,
260  0);
261  if (!NT_SUCCESS(Status))
262  {
263  DPRINT1("Could not open volume '%wZ' to obtain its file system, Status 0x%08lx\n",
264  VolumePathU, Status);
265  return Status;
266  }
267 
269  &IoStatusBlock,
270  FileFsAttribute,
271  sizeof(Buffer),
274 
275  if (!NT_SUCCESS(Status))
276  {
277  DPRINT1("NtQueryVolumeInformationFile() failed, Status 0x%08lx\n", Status);
278  return Status;
279  }
280 
281  if (FileSystemNameSize >= FileFsAttribute->FileSystemNameLength + sizeof(WCHAR))
282  {
283  RtlCopyMemory(FileSystemName,
284  FileFsAttribute->FileSystemName,
285  FileFsAttribute->FileSystemNameLength);
286  FileSystemName[FileFsAttribute->FileSystemNameLength / sizeof(WCHAR)] = UNICODE_NULL;
287  }
288  else
289  {
291  }
292 
293  return STATUS_SUCCESS;
294 }
#define FILE_GENERIC_READ
Definition: nt_native.h:653
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
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:125
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
HANDLE FileHandle
Definition: stats.c:38
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI NtQueryVolumeInformationFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID FsInformation, IN ULONG Length, IN FS_INFORMATION_CLASS FsInformationClass)
Definition: iofunc.c:4084
Definition: bufpool.h:45
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:26
struct _FILE_FS_ATTRIBUTE_INFORMATION * PFILE_FS_ATTRIBUTE_INFORMATION
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by CheckVolume().

◆ OpenKeyboard()

static NTSTATUS OpenKeyboard ( OUT PHANDLE  KeyboardHandle)
static

Definition at line 128 of file autochk.c.

130 {
133  UNICODE_STRING KeyboardName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardClass0");
134 
135  /* Just open the class driver */
137  &KeyboardName,
138  0,
139  NULL,
140  NULL);
141  return NtOpenFile(KeyboardHandle,
144  &IoStatusBlock,
145  FILE_OPEN,
146  0);
147 }
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:62
smooth NULL
Definition: ftsmooth.c:416
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 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 71 of file autochk.c.

72 {
73  INT Len;
74  char buffer[512];
75  va_list ap;
78 
79  va_start(ap, fmt);
80  Len = vsprintf(buffer, fmt, ap);
81  va_end(ap);
82 
85  &AnsiString,
86  TRUE);
89 
90  return Len;
91 }
#define TRUE
Definition: types.h:120
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1980
GLuint buffer
Definition: glext.h:5915
int32_t INT
Definition: typedefs.h:56
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)
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
#define va_start(ap, A)
Definition: acmsvcex.h:91
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 496 of file autochk.c.

498 {
500 
503  QueryTable[0].Name = L"AutoChkTimeOut";
504  QueryTable[0].EntryContext = TimeOut;
505 
507  /* See: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/autochk */
508  *TimeOut = min(max(*TimeOut, 0), 259200);
509 }
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4004
#define max(a, b)
Definition: svc.c:63
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
static const WCHAR L[]
Definition: oid.c:1250
#define min(a, b)
Definition: monoChain.cc:55
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#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 150 of file autochk.c.

153 {
157  KEYBOARD_INPUT_DATA InputData;
158  INT Len = 0;
159 
160  /* Skip the wait if there is no timeout */
161  if (TimeOut <= 0)
162  return STATUS_TIMEOUT;
163 
164  /* Attempt to read a down key-press from the keyboard */
165  do
166  {
167  Offset.QuadPart = 0;
169  NULL,
170  NULL,
171  NULL,
172  &IoStatusBlock,
173  &InputData,
174  sizeof(KEYBOARD_INPUT_DATA),
175  &Offset,
176  NULL);
177  if (!NT_SUCCESS(Status))
178  {
179  /* Something failed, bail out */
180  return Status;
181  }
182  if ((Status != STATUS_PENDING) && !(InputData.Flags & KEY_BREAK))
183  {
184  /* We have a down key-press, return */
185  return Status;
186  }
187  } while (Status != STATUS_PENDING);
188 
189  /* Perform the countdown of TimeOut seconds */
191  while (TimeOut > 0)
192  {
193  /*
194  * Display the countdown string.
195  * Note that we only do a carriage return to go back to the
196  * beginning of the line to possibly erase it. Note also that
197  * we display a trailing space to erase any last character
198  * when the string length decreases.
199  */
200  Len = PrintString("Press any key within %d second(s) to cancel and resume startup. \r", TimeOut);
201 
202  /* Decrease the countdown */
203  --TimeOut;
204 
205  /* Wait one second for a key press */
206  Timeout.QuadPart = -10000000;
208  if (Status != STATUS_TIMEOUT)
209  break;
210  }
211 
212  /* Erase the countdown string */
213  EraseLine(Len);
214 
215  if (Status == STATUS_TIMEOUT)
216  {
217  /* The user did not press any key, cancel the read */
219  }
220  else
221  {
222  /* Otherwise, return some status */
224  }
225 
226  return Status;
227 }
HANDLE KeyboardHandle
Definition: autochk.c:62
LONG NTSTATUS
Definition: precomp.h:26
static INT PrintString(char *fmt,...)
Definition: autochk.c:71
#define KEY_BREAK
Definition: ntddkbd.h:71
int32_t INT
Definition: typedefs.h:56
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
static VOID EraseLine(IN INT LineLength)
Definition: autochk.c:94
#define Len
Definition: deflate.h:82
Status
Definition: gdiplustypes.h:24
static ULONG Timeout
Definition: ping.c:61
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
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[10]
Initial value:
=
{
{ L"FAT", VfatChkdsk },
{ L"FAT32", VfatChkdsk },
{ L"NTFS", NtfsChkdsk },
{ L"EXT2", Ext2Chkdsk },
{ L"EXT3", Ext2Chkdsk },
{ L"EXT4", Ext2Chkdsk },
{ L"Btrfs", BtrfsChkdskEx },
{ L"RFSD", ReiserfsChkdsk },
{ L"FFS", FfsChkdsk },
{ L"CDFS", CdfsChkdsk },
}
NTSTATUS NTAPI NtfsChkdsk(IN PUNICODE_STRING DriveRoot, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
Definition: ntfslib.c:27
NTSTATUS NTAPI ReiserfsChkdsk(IN PUNICODE_STRING DriveRoot, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
Definition: reiserfslib.c:27
NTSTATUS NTAPI BtrfsChkdskEx(IN PUNICODE_STRING DriveRoot, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI FfsChkdsk(IN PUNICODE_STRING DriveRoot, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
Definition: ffslib.c:27
NTSTATUS NTAPI Ext2Chkdsk(IN PUNICODE_STRING DriveRoot, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
Definition: Mke2fs.c:1008
NTSTATUS NTAPI VfatChkdsk(IN PUNICODE_STRING DriveRoot, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
Definition: vfatlib.c:375
NTSTATUS NTAPI CdfsChkdsk(IN PUNICODE_STRING DriveRoot, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
Definition: cdfslib.c:16

Definition at line 48 of file autochk.c.

Referenced by CheckVolume(), and GetFileSystemByName().

◆ KeyboardHandle

HANDLE KeyboardHandle = NULL

Definition at line 62 of file autochk.c.

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