vc 下如何访问mbr呀?

vosine 2006-07-14 12:06:54
我要在vc环境下访问一个硬盘的mbr, 比如清空或者保存
有源码最好, 谢谢
...全文
213 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pp7765 2006-07-15
  • 打赏
  • 举报
回复
文件名用\\.\PHYSICALDRIVE0或者\\.\PHYSICALDRIVE1
DentistryDoctor 2006-07-14
  • 打赏
  • 举报
回复
用CreateFile打开相应的物理盘,然后读写第一个扇区即可。

不过,建议只读,写的后果楼主应该知道。
DentistryDoctor 2006-07-14
  • 打赏
  • 举报
回复
Physical Disks and Volumes

You can use the CreateFile function to open a physical disk drive or a volume. The function returns a handle that can be used with the DeviceIoControl function. This enables you to access the disk partition table. However, it is potentially dangerous to do so, because an incorrect write to a disk could make its contents inaccessible. The following requirements must be met for such a call to succeed:


The caller must have administrative privileges. For more information, see Running with Special Privileges.
The dwCreationDisposition parameter must have the OPEN_EXISTING flag.
When opening a volume or floppy disk, the dwShareMode parameter must have the FILE_SHARE_WRITE flag.
When opening a physical drive x, the lpFileName string should be the following form: \\.\PHYSICALDRIVE<x>. Hard disk numbers start at 0 (zero). The following table shows some examples of physical drive strings.

String Meaning
\\.\PHYSICALDRIVE0 Opens the first physical drive.
\\.\PHYSICALDRIVE2 Opens the third physical drive.

For an example of opening a physical drive, see Calling DeviceIoControl.

When opening a volume or floppy drive, the lpFileName string should be the following form: \\.\<x>:. Do not use a trailing backslash, which indicates the root directory of a drive. The following table shows some examples of drive strings.

String Meaning
\\.\A: Opens drive A (floppy drive).
\\.\C: Opens drive C (volume).

You can also open a volume by referring to its volume name. For more information, see Naming a Volume.

Volume handles can be opened as noncached at the discretion of the file system, even when the noncached option is not specified in CreateFile. You should assume that all Microsoft file systems open volume handles as noncached. The restrictions on noncached I/O for files also apply to volumes.

A file system may or may not require buffer alignment even though the data is noncached. However, if the noncached option is specified when opening a volume, buffer alignment is enforced regardless of the file system on the volume. It is recommended on all file systems that you open volume handles as noncached, and follow the noncached I/O restrictions.

请楼主读MSDN时仔细一些。另外需要说明的是,这些操作都是需要管理员权限的。
vosine 2006-07-14
  • 打赏
  • 举报
回复
createfile 可以打开物理区么?那一个属性是说明物理区呀?
我怕读的可能仅仅是逻辑区的第一个扇区吧?

2,641

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧