如何实现对u盘物理扇区的写操作?

vcPlayer 2008-06-19 04:01:44
RT.

刚看见,对不住了!
...全文
114 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
alphapiao 2008-07-02
  • 打赏
  • 举报
回复
如果是xp系统,写U盘与与硬盘是一样的,用CreateFile打开U盘,用WriteFile可以写。
如果是vista系统,需要写驱动,因为vista不允许直接写物理硬盘,可以直接读物理硬盘。
vcPlayer 2008-06-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 shada 的回复:]
winhex应该可以。
自己实现可能要用到驱动技术。
[/Quote]

顶一个.....
CathySun118 2008-06-21
  • 打赏
  • 举报
回复
from msdn:

WriteLogicalSectors (hDev, bDrive, dwStartSector, wSectors, lpSectBuff)

Purpose:
Writes sectors to a logical drive. Uses Int 26h

Parameters:
hDev
Handle of VWIN32

bDrive
The MS-DOS logical drive number. 1 = A, 2 = B, 3 = C, etc.

dwStartSector
The first logical sector to write

wSectors
The number of sectors to write

lpSectBuff
The caller-supplied buffer that contains the sector data

Return Value:
Returns TRUE if successful, or FALSE if failure.

Comments:
This function does not validate its parameters.
------------------------------------------------------------------*/
BOOL WriteLogicalSectors (HANDLE hDev,
BYTE bDrive,
DWORD dwStartSector,
WORD wSectors,
LPBYTE lpSectBuff)
{
BOOL fResult;
DWORD cb;
DIOC_REGISTERS reg = {0};
DISKIO dio = {0};

dio.dwStartSector = dwStartSector;
dio.wSectors = wSectors;
dio.dwBuffer = (DWORD)lpSectBuff;

reg.reg_EAX = bDrive - 1; // Int 26h drive numbers are 0-based.
reg.reg_EBX = (DWORD)&dio;
reg.reg_ECX = 0xFFFF; // use DISKIO struct

fResult = DeviceIoControl(hDev, VWIN32_DIOC_DOS_INT26,
®, sizeof(reg),
®, sizeof(reg), &cb, 0);

// Determine if the DeviceIoControl call and the write succeeded.
fResult = fResult && !(reg.reg_Flags & CARRY_FLAG);

return fResult;
}
shada 2008-06-20
  • 打赏
  • 举报
回复
winhex应该可以。
自己实现可能要用到驱动技术。
vcPlayer 2008-06-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 vcPlayer 的回复:]
沉得太快! 放到月底。。。
[/Quote]
vcPlayer 2008-06-20
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 shada 的回复:]
winhex应该可以。
自己实现可能要用到驱动技术。
[/Quote]

欢迎, 继续.......:)
vcPlayer 2008-06-19
  • 打赏
  • 举报
回复
沉得太快! 放到月底。。。
vcPlayer 2008-06-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cnzdgs 的回复:]
什么意思?
程序要有管理员权限;CreateFile打开\\.\盘符,WriteFile,CloseHandle;做得完整一点需要写之前LOCK,写完后DISMOUNT。
[/Quote]

呵呵,谢谢!
cnzdgs 2008-06-19
  • 打赏
  • 举报
回复
什么意思?
程序要有管理员权限;CreateFile打开\\.\盘符,WriteFile,CloseHandle;做得完整一点需要写之前LOCK,写完后DISMOUNT。

2,641

社区成员

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

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