Added partinfo application.
authorEric Kohl <eric.kohl@reactos.org>
Sat, 25 Aug 2001 17:03:30 +0000 (17:03 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 25 Aug 2001 17:03:30 +0000 (17:03 +0000)
svn path=/trunk/; revision=2199

reactos/Makefile
reactos/apps/utils/partinfo/makefile [new file with mode: 0644]
reactos/apps/utils/partinfo/partinfo.c [new file with mode: 0644]
reactos/install.bat

index f37699d..70f82b1 100644 (file)
@@ -59,7 +59,7 @@ SYS_APPS = services shell winlogon
 
 APPS = args hello test cat bench apc shm lpc thread event file gditest \
        pteb consume dump_shared_data vmtest regtest alive mstest nptest \
-       objdir atomtest winhello
+       objdir atomtest winhello partinfo
 
 #NET_APPS = ping roshttpd telnet
 NET_APPS = ping roshttpd
diff --git a/reactos/apps/utils/partinfo/makefile b/reactos/apps/utils/partinfo/makefile
new file mode 100644 (file)
index 0000000..99e812f
--- /dev/null
@@ -0,0 +1,23 @@
+# $Id: makefile,v 1.1 2001/08/25 17:02:21 ekohl Exp $
+
+PATH_TO_TOP = ../..
+
+TARGET_NORC = yes
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = partinfo
+
+#TARGET_CFLAGS = -fnative_struct
+
+TARGET_SDKLIBS = kernel32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/reactos/apps/utils/partinfo/partinfo.c b/reactos/apps/utils/partinfo/partinfo.c
new file mode 100644 (file)
index 0000000..c7e95fd
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * partinfo - partition info program
+ */
+
+#include <windows.h>
+//#include <winioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+//#define DUMP_DATA
+#define DUMP_SIZE_INFO
+
+
+#ifdef DUMP_DATA
+void HexDump(char *buffer, ULONG size)
+{
+  ULONG offset = 0;
+  unsigned char *ptr;
+
+  while (offset < (size & ~15))
+    {
+      ptr = (unsigned char*)((ULONG)buffer + offset);
+      printf("%08lx  %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx-%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx\n",
+            offset,
+            ptr[0],
+            ptr[1],
+            ptr[2],
+            ptr[3],
+            ptr[4],
+            ptr[5],
+            ptr[6],
+            ptr[7],
+            ptr[8],
+            ptr[9],
+            ptr[10],
+            ptr[11],
+            ptr[12],
+            ptr[13],
+            ptr[14],
+            ptr[15]);
+      offset += 16;
+    }
+
+  ptr = (unsigned char*)((ULONG)buffer + offset);
+  printf("%08lx ", offset);
+  while (offset < size)
+    {
+      printf(" %02hx", *ptr);
+      offset++;
+      ptr++;
+    }
+
+  printf("\n\n\n");
+}
+#endif
+
+int main (int argc, char *argv[])
+{
+  HANDLE hDisk;
+  DWORD dwRead;
+  DWORD i;
+  char *Buffer;
+  DRIVE_LAYOUT_INFORMATION *LayoutBuffer;
+  DISK_GEOMETRY DiskGeometry;
+
+  hDisk = CreateFile("\\\\.\\PHYSICALDRIVE0",
+                    GENERIC_READ,
+                    FILE_SHARE_READ | FILE_SHARE_WRITE,
+                    NULL,
+                    OPEN_EXISTING,
+                    0,
+                    NULL);
+  if (hDisk == INVALID_HANDLE_VALUE)
+    {
+      printf("Invalid disk handle!");
+      return 0;
+    }
+
+
+  /* get drive geometry */
+  if (!DeviceIoControl(hDisk,
+                      IOCTL_DISK_GET_DRIVE_GEOMETRY,
+                      NULL,
+                      0,
+                      &DiskGeometry,
+                      sizeof(DISK_GEOMETRY),
+                      &dwRead,
+                      NULL))
+    {
+      CloseHandle(hDisk);
+      printf("DeviceIoControl failed! Error: %u\n",
+            GetLastError());
+      free(Buffer);
+      return 0;
+    }
+
+#ifdef DUMP_DATA
+  HexDump((char*)&DiskGeometry, dwRead);
+#endif
+  printf("Cylinders: %I64u\nMediaType: %lx\nTracksPerCylinder: %lu\n"
+        "SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n",
+        DiskGeometry.Cylinders.QuadPart,
+        DiskGeometry.MediaType,
+        DiskGeometry.TracksPerCylinder,
+        DiskGeometry.SectorsPerTrack,
+        DiskGeometry.BytesPerSector);
+
+
+  Buffer = (char*)malloc(8192);
+  if (Buffer == NULL)
+    {
+      CloseHandle(hDisk);
+      printf("Out of memory!");
+      return 0;
+    }
+  memset(Buffer, 0, 8192);
+
+  if (!DeviceIoControl(hDisk,
+                      IOCTL_DISK_GET_DRIVE_LAYOUT,
+                      NULL,
+                      0,
+                      Buffer,
+                      8192,
+                      &dwRead,
+                      NULL))
+    {
+      CloseHandle(hDisk);
+      printf("DeviceIoControl failed! Error: %u\n",
+            GetLastError());
+      free(Buffer);
+      return 0;
+    }
+
+  CloseHandle(hDisk);
+
+#ifdef DUMP_DATA
+  HexDump(Buffer, dwRead);
+#endif
+
+  LayoutBuffer = (DRIVE_LAYOUT_INFORMATION*)Buffer;
+
+  printf("Partitions %u  Signature %x\n",
+        LayoutBuffer->PartitionCount,
+        LayoutBuffer->Signature);
+
+  for (i = 0; i < LayoutBuffer->PartitionCount; i++)
+    {
+      printf(" %d: nr: %d boot: %1x type: %x start: 0x%I64x count: 0x%I64x\n",
+            i,
+            LayoutBuffer->PartitionEntry[i].PartitionNumber,
+            LayoutBuffer->PartitionEntry[i].BootIndicator,
+            LayoutBuffer->PartitionEntry[i].PartitionType,
+            LayoutBuffer->PartitionEntry[i].StartingOffset.QuadPart,
+            LayoutBuffer->PartitionEntry[i].PartitionLength.QuadPart);
+    }
+
+#ifdef DUMP_SIZE_INFO
+  printf("\nsizeof(PARTITION_INFORMATION): %lu\n", sizeof(PARTITION_INFORMATION));
+#endif
+
+  free(Buffer);
+
+  return 0;
+}
index 70b2b1c..f83135d 100644 (file)
@@ -76,6 +76,7 @@ copy apps\mstest\msclient.exe %ROS_INSTALL%\bin
 copy apps\nptest\npserver.exe %ROS_INSTALL%\bin
 copy apps\nptest\npclient.exe %ROS_INSTALL%\bin
 copy apps\atomtest\atomtest.exe %ROS_INSTALL%\bin
+copy apps\partinfo\partinfo.exe %ROS_INSTALL%\bin
 copy apps\net\ping\ping.exe %ROS_INSTALL%\bin
 copy apps\net\roshttpd\roshttpd.exe %ROS_INSTALL%\bin
 copy apps\net\telnet\telnet.exe %ROS_INSTALL%\bin