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

65 lines
1.8 KiB

  1. #include <windows.h>
  2. #include <winioctl.h>
  3. #include <stdio.h>
  4. #include <ftapi.h>
  5. void __cdecl
  6. main(
  7. int argc,
  8. char** argv
  9. )
  10. {
  11. TCHAR dosDriveName[10];
  12. HANDLE h;
  13. BOOL b;
  14. PARTITION_INFORMATION partInfo;
  15. DWORD bytes;
  16. DISK_GEOMETRY geometry;
  17. LONGLONG newSectors;
  18. if (argc != 2) {
  19. printf("usage: %s drive:\n", argv[0]);
  20. return;
  21. }
  22. if (argv[1][1] != ':' || argv[1][2] != 0) {
  23. printf("usage: %s drive:\n", argv[0]);
  24. return;
  25. }
  26. wsprintf(dosDriveName, TEXT("\\\\.\\%c:"), argv[1][0]);
  27. h = CreateFile(dosDriveName, GENERIC_READ,
  28. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
  29. FILE_ATTRIBUTE_NORMAL, INVALID_HANDLE_VALUE);
  30. if (h == INVALID_HANDLE_VALUE) {
  31. printf("Can't open, failed with %d\n", GetLastError());
  32. return;
  33. }
  34. b = DeviceIoControl(h, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0,
  35. &partInfo, sizeof(partInfo), &bytes, NULL);
  36. if (!b) {
  37. printf("Can't read partition info, failed with %d\n", GetLastError());
  38. return;
  39. }
  40. b = DeviceIoControl(h, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
  41. &geometry, sizeof(geometry), &bytes, NULL);
  42. if (!b) {
  43. printf("Can't read geometry info, failed with %d\n", GetLastError());
  44. return;
  45. }
  46. newSectors = partInfo.PartitionLength.QuadPart/geometry.BytesPerSector;
  47. b = DeviceIoControl(h, FSCTL_EXTEND_VOLUME, &newSectors, sizeof(newSectors),
  48. NULL, 0, &bytes, NULL);
  49. if (b) {
  50. printf("File system extended successfully.\n");
  51. } else {
  52. printf("File system extension failed.\n");
  53. }
  54. }