From: jpuopolo on
All,

I've been an application and middle-tier developer for most of my career (20
yrs), and am now exploring kernel-level development, which I'm finding
fascinating. Along these lines, I have a basic question:

Let's suppose I wanted to read the Master Boot Record (MBR) from my hard
drive. Is this possible from user-mode code, or would I need to write a
device driver? How would I about doing this? Are there common APIs I need to
get familiar with to accomplish this type of function?

Thanks,
John



From: Maxim S. Shatskih on
> Let's suppose I wanted to read the Master Boot Record (MBR) from my hard
> drive. Is this possible from user-mode code, or would I need to write a
> device driver? How would I about doing this? Are there common APIs I need to
> get familiar with to accomplish this type of function?

Open \\.\PhysicalDrive%d and write to offset 0. Then call IOCTL_DISK_UPDATE_PROPERTIES for Disk/PartMgr drivers to re-read the updated MBR.

Or use IOCTL_DISK_SET_DRIVE_LAYOUT(_EX), which will send the command to Disk/PartMgr in the kernel and it, in turn, will do the job.

--
Maxim S. Shatskih
Windows DDK MVP
maxim(a)storagecraft.com
http://www.storagecraft.com

From: jpuopolo on
Hi Maxim,

Thanks for the quick reply.
What API function would I use to perform the "open"?

John


"Maxim S. Shatskih" wrote:

> > Let's suppose I wanted to read the Master Boot Record (MBR) from my hard
> > drive. Is this possible from user-mode code, or would I need to write a
> > device driver? How would I about doing this? Are there common APIs I need to
> > get familiar with to accomplish this type of function?
>
> Open \\.\PhysicalDrive%d and write to offset 0. Then call IOCTL_DISK_UPDATE_PROPERTIES for Disk/PartMgr drivers to re-read the updated MBR.
>
> Or use IOCTL_DISK_SET_DRIVE_LAYOUT(_EX), which will send the command to Disk/PartMgr in the kernel and it, in turn, will do the job.
>
> --
> Maxim S. Shatskih
> Windows DDK MVP
> maxim(a)storagecraft.com
> http://www.storagecraft.com
>
>
From: David Craig on
1. CreateFile (recommended)
2. NtCreateFile
3. ZwCreateFile

You said you were an experienced user mode programmer. Re-read the MSDN
Library documentation on CreateFile at least 5 times making sure you read
every word in the topic and follow all links. It is far more complex than
most can believe especially those without kernel mode experience.

"jpuopolo" <jpuopolo(a)discussions.microsoft.com> wrote in message
news:A94EA8BC-655A-4C68-9054-E13CBCF3C3F8(a)microsoft.com...
> Hi Maxim,
>
> Thanks for the quick reply.
> What API function would I use to perform the "open"?
>
> John
>
>
> "Maxim S. Shatskih" wrote:
>
>> > Let's suppose I wanted to read the Master Boot Record (MBR) from my
>> > hard
>> > drive. Is this possible from user-mode code, or would I need to write a
>> > device driver? How would I about doing this? Are there common APIs I
>> > need to
>> > get familiar with to accomplish this type of function?
>>
>> Open \\.\PhysicalDrive%d and write to offset 0. Then call
>> IOCTL_DISK_UPDATE_PROPERTIES for Disk/PartMgr drivers to re-read the
>> updated MBR.
>>
>> Or use IOCTL_DISK_SET_DRIVE_LAYOUT(_EX), which will send the command to
>> Disk/PartMgr in the kernel and it, in turn, will do the job.
>>
>> --
>> Maxim S. Shatskih
>> Windows DDK MVP
>> maxim(a)storagecraft.com
>> http://www.storagecraft.com
>>
>>


From: jpuopolo on
David,

Thanks. I will look again at this function. My own research took me down the
path toward DeviceIoControl, but I'm just beginning to piece together the
various componets.

Much appreciated,
John


"David Craig" wrote:

> 1. CreateFile (recommended)
> 2. NtCreateFile
> 3. ZwCreateFile
>
> You said you were an experienced user mode programmer. Re-read the MSDN
> Library documentation on CreateFile at least 5 times making sure you read
> every word in the topic and follow all links. It is far more complex than
> most can believe especially those without kernel mode experience.
>
> "jpuopolo" <jpuopolo(a)discussions.microsoft.com> wrote in message
> news:A94EA8BC-655A-4C68-9054-E13CBCF3C3F8(a)microsoft.com...
> > Hi Maxim,
> >
> > Thanks for the quick reply.
> > What API function would I use to perform the "open"?
> >
> > John
> >
> >
> > "Maxim S. Shatskih" wrote:
> >
> >> > Let's suppose I wanted to read the Master Boot Record (MBR) from my
> >> > hard
> >> > drive. Is this possible from user-mode code, or would I need to write a
> >> > device driver? How would I about doing this? Are there common APIs I
> >> > need to
> >> > get familiar with to accomplish this type of function?
> >>
> >> Open \\.\PhysicalDrive%d and write to offset 0. Then call
> >> IOCTL_DISK_UPDATE_PROPERTIES for Disk/PartMgr drivers to re-read the
> >> updated MBR.
> >>
> >> Or use IOCTL_DISK_SET_DRIVE_LAYOUT(_EX), which will send the command to
> >> Disk/PartMgr in the kernel and it, in turn, will do the job.
> >>
> >> --
> >> Maxim S. Shatskih
> >> Windows DDK MVP
> >> maxim(a)storagecraft.com
> >> http://www.storagecraft.com
> >>
> >>
>
>
>
 |  Next  |  Last
Pages: 1 2
Prev: NDIS 6.0 - Filter driver
Next: USB device