Re: Retrieving the filesystem name of each partition not mounted



On Feb 19, 2:08 pm, I.You <I...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Thanks a lot, David and Don.

I need a lot studies...



"Don Burn" wrote:
As David said, without kernel code you are doomed. First note, you are
trying to break the Windows model since you should have a file system
recognizer (a kernel driver) that recognizes and loads the file system. I
have had the pain of dealing with a crappy solution like you are trying (it
wiped out a valid file system I was working on!).

The place to ask file system questions is NTFSD at
http://www.osronline.com/

--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

"David Craig" <d...@xxxxxxxxxxxxx> wrote in message
news:OzGQ71eUHHA.4632@xxxxxxxxxxxxxxxxxxxxxxx
This is the wrong group for this type of discussion. The is a win32
newsgroup which means a Windows application and the win32k.sys driver and
its calling DLLs. File systems are not a part of this arena. If you
can't write kernel mode code, then you are doomed to failure since you
state: "Retrieving the filesystem name or something of each partition
which is not mounted". All partitions are mounted and I would suggest
you look into the raw file system. I have heard of using an Explorer
extension to permit access to non supported file systems, but that is not
a real file system and it is not available to any other programs.

"I.You" <I...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5C369229-C266-4A2C-ADB6-70153E4B55E6@xxxxxxxxxxxxxxxx
Hi everyone.

What I'm trying to do is that detecting all disks and all partitions
(mounted or not) in system and then mounting (and assigning a drive
letter)
the partition if it's ext2 filesystem.
So I try to write the APPLICATION program, which loads the ext2
filesystem
driver for windows.

In order to do this, I tried to use a few DDK functions (Nt***
functions)
but it's failed. So now I'm trying to use GetVolumeInformation but it's
not
good too.

I have no idea what to do. Is there any good idea?

Anyway, I'm considering as follow:

1. Retrieving currently assigned drive letters (including CD-ROM drive).
Q: Is it possible for "QueryDosDevice" to detect CD-ROM drive? If not,
other
ways?

2. Retrieving the number of disks and partitions in each disk in system.
Q: IOCTL_DISK_GET_DRIVE_LAYOUT_EX is for Retrieving the number of
partitions, then the number of disks?

3. Retrieving the filesystem name or something of each partition which
is
not mounted.
Q: Is it possible to retrieve the filesystem name of each partition by
using
DeviceIoControl? However, I wonder how to retrieve information about
each
partition in DeviceIoControl, since the device it handles is not each
partition but filesystem driver.

I have no idea how to solve this because I'm a beginner.
So I think writing my own kernel-mode module is too difficult.

I wish your good advices.- Hide quoted text -

- Show quoted text -

Finding number of Disks:

CString HDDetails(int* HDCount)
{
int index=0;
HANDLE hDevice;
CString Result;
CString HardDisk;
DWORD junk;
DISK_GEOMETRY pdg;

HardDisk.Format(L"\\\\.\\PhysicalDrive%d",index);

hDevice=CreateFile(HardDisk,0,FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,OPEN_EXISTING,0,NULL);

if (hDevice==INVALID_HANDLE_VALUE)
Result="Error: Can not Query Hard Disk Drives.";

while (hDevice!=INVALID_HANDLE_VALUE)
{
BOOL bResult=DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_GEOMETRY,
NULL,0,
&pdg,sizeof(DISK_GEOMETRY),
&junk,
(LPOVERLAPPED) NULL);

if (bResult)
{
CString Temp;
Temp.Format(L"--- Hard Disk No. %d ---\r\n",index+1);
Result+=Temp;

Temp.Format(L"Cylinders: %I64d\r\n",pdg.Cylinders);
Result+=Temp;

Temp.Format(L"Tracks per cylinder: %ld\r\n",(ULONG)
pdg.TracksPerCylinder);
Result+=Temp;

Temp.Format(L"Sectors per track: %ld\r\n",(ULONG)
pdg.SectorsPerTrack);
Result+=Temp;

Temp.Format(L"Bytes per sector: %ld\r\n",(ULONG)
pdg.BytesPerSector);
Result+=Temp;

ULONGLONG DiskSize=pdg.Cylinders.QuadPart * (ULONG)
pdg.TracksPerCylinder *
(ULONG) pdg.SectorsPerTrack * (ULONG) pdg.BytesPerSector;

Temp.Format(L"Total size: %I64d (Bytes) -> %I64d (MB) -> %I64d (GB)
\r\n\r\n",DiskSize,
DiskSize/1024/1024, DiskSize/1024/1024/1024);
Result+=Temp;
}


CloseHandle(hDevice);

index++;
HardDisk.Format(L"\\\\.\\PhysicalDrive%d",index);
hDevice=CreateFile(HardDisk,0,FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,OPEN_EXISTING,0,NULL);
}

CString Temp;
Temp.Format(L"Number of Hard Disk Drives: %d\r\n\r\n",index);
Result=Temp+Result;

*HDCount = index;
return Result;
}


Number of Partitions:

CString QueryPartitions()
{
int index=0;
HANDLE hDevice;
CString Result;
CString HardDisk;
DWORD junk = 0;
//DRIVE_LAYOUT_INFORMATION_EX dli, *pdli;
//WCHAR dli1[sizeof(DRIVE_LAYOUT_INFORMATION_EX) + MAX_PARTITIONS *
sizeof(PARTITION_INFORMATION_EX)];
//ZeroMemory(&dli1, sizeof(dli1));
//dli.

DRIVE_LAYOUT_INFORMATION_EX dli2[1000];
DRIVE_LAYOUT_INFORMATION_EX dli;
ZeroMemory(dli2, 1000 * sizeof(DRIVE_LAYOUT_INFORMATION_EX));

HardDisk.Format(L"\\\\.\\PhysicalDrive%d",index);

hDevice=CreateFile(HardDisk,0,FILE_SHARE_READ,
NULL,OPEN_EXISTING,0,NULL);

if (hDevice==INVALID_HANDLE_VALUE)
Result="Error: Can not Query Partitions.";

while (hDevice!=INVALID_HANDLE_VALUE)
{
BOOL bResult=DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_LAYOUT_EX,
NULL,0,
dli2, 1000 * sizeof(DRIVE_LAYOUT_INFORMATION_EX),
&junk,
(LPOVERLAPPED) NULL);

if (bResult)
{
CString Temp;
//pdli = (DRIVE_LAYOUT_INFORMATION_EX *)dli1;
//dli = *pdli;

dli = dli2[0];

Temp.Format(L"Number of partitions in physical disk %d is %d\r
\n",index+1, dli.PartitionCount);
Result+=Temp;

for (DWORD iCounter=0;iCounter<dli.PartitionCount;iCounter++)
{
Temp.Format(L"\r\nPartition No.: %d", iCounter);
Result+=Temp;

switch (dli.PartitionStyle)
{
case PARTITION_STYLE_MBR:
Temp.Format(L"Partition Style: MBR "
L"(standard AT-style master boot records)\r\n");
Result+=Temp;
Temp.Format(L"Signature: %ld\r\n", dli.Mbr.Signature);
Result+=Temp;
break;

case PARTITION_STYLE_GPT:
Temp.Format(L"Partition Style: GPT\r\n");
Result+=Temp;
WCHAR guid[100];
StringFromGUID2(dli.Gpt.DiskId, guid, 100);
Temp.Format(L"Disk ID: %s\r\n", guid);
Result+=Temp;
Temp.Format(L"Starting byte offset of the first usable block:
%I64d\r\n", dli.Gpt.StartingUsableOffset);
Result+=Temp;
Temp.Format(L"Size of the usable blocks on the disk (bytes): %I64d
\r\n", dli.Gpt.UsableLength);
Result+=Temp;
Temp.Format(L"Maximum number of partitions that can be defined in
the usable block: %d", dli.Gpt.MaxPartitionCount);
Result+=Temp;
break;

case PARTITION_STYLE_RAW:
Temp.Format(L"Partition Style: RAW "
L"(Partition not formatted in either of "
L"the recognized formats-MBR or GPT\r\n");
Result+=Temp;
break;

default:
Temp.Format(L"Not recognized\r\n");
Result+=Temp;
} //switch

_tprintf(_T("\Partitons details %s"),Result);

} //for
} //if
else
{
LPSTR MessageBuffer;

DWORD dwFormatFlags=FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM ;

FormatMessageA(dwFormatFlags, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &MessageBuffer,
0, NULL);

Result+=MessageBuffer;
LocalFree(MessageBuffer);
}

CloseHandle(hDevice);

index++;
HardDisk.Format(L"\\\\.\\PhysicalDrive%d",index);
hDevice=CreateFile(HardDisk,0,FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,OPEN_EXISTING,0,NULL);
} //while


return Result;
}


Type of Disks : Removable / CDROM etc

driveType = GetDriveType("c:\\");
switch (driveType)
{
case 0:
cout << "error\n";
break;
case 1:
cout << "Drive does not exist\n";
break;
case DRIVE_REMOVABLE:
cout << "Media removable\n";
break;
case DRIVE_FIXED:
cout << "Fixed disk\n";
break;
case DRIVE_REMOTE:
cout << "Network drive\n";
break;
case DRIVE_CDROM:
cout << "CD-ROM drive\n";
break;
case DRIVE_RAMDISK:
cout << "RAM disk\n";
break;
}


Finding Logical mapping

void main()
{
DWORD len;
char buffer[1000];
char *p;

len = GetLogicalDriveStrings(1000, buffer);
cout << "Logical drives on this machine: \n";
for (p=buffer; *p != '\0'; p++)
{
cout << p << endl;
while (*p != '\0') p++;
}
}


Thanks
Vikrant

.



Relevant Pages

  • Re: Cannot Convert to NTFS
    ... The HELP file says that a complete list of error codes is on the PQ site, ... i am having a problem with converting the file system from FAT To NTFS, ... Basically i am using windows ... and Linux on the third partition. ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Chkdsk errors in SP2 installation
    ... Windows is on the first partition (that's the one I ... > the Error Checker in the disk Properties/Tools says the disk is OK. ... >>Windows found problems with the file system. ...
    (microsoft.public.windowsxp.general)
  • Re: Windows XP Virtual File System Driver - HOW TO WRITE ONE??
    ... have written several Windows drivers and taken the OSR class, ... Windows file system, so your comparision is inappropriate and wrong. ... Windows 2k/XP/2k3 Filesystem and Driver Consulting ...
    (microsoft.public.development.device.drivers)
  • Re: Converting from Fat32 to NTFS
    ... Choosing between NTFS, FAT, and FAT32 ... running Windows XP: NTFS, FAT, and FAT32. ... NTFS is the recommended file system for the following reasons: ... you have a FAT or FAT32 partition, it is recommended that you format the ...
    (microsoft.public.windowsxp.general)
  • Re: Hey Mark!
    ... the so-called "GUID Partition Table", ... and the File System Therein - ... You can force Windows to use an older FAT file system, ... when booted from the Mac partition. ...
    (comp.sys.mac.system)

Loading