Win2000下直接读写磁盘扇区
来源:互联网 发布:mac大写字母切换知乎 编辑:程序博客网 时间:2024/05/21 08:36
在NT和2000下,通过CreateFile来打开需要读写的驱动器,ReadFile、WriteFile来进行磁盘读写。
下面的代码演示了,如何读写A驱
/* -----------------------------------------------------
Read Floppy Disk Sector for win NT/2000
reads [numsec] sectors from [head] [track] [sector]
-------------------------------------------------------*/
char* ReadSectors(int head, int sector, int track, int numsec)
{
// getting logical sector from absolute head/track/sector ...
//计算扇区位置
int LogicalSector = (sector-1) +
(head*SECTORSPERTRACK) +
(track*SECTORSPERTRACK*NUMOFHEADS) ;
char *buffer ;
HANDLE hDevice ;
HANDLE hDevice;
char* buffer = (char*)malloc (512*numsec);
strset ( buffer , ' ');
DWORD bytesread ;
// getting a handle to the drive a: using
// CreateFile () function ....
//打开驱动器 //./A:
hDevice = CreateFile("////.//A:",
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == NULL)
{
MessageBox ("Failed !");
return NULL;
}
// setting the file pointer to the start of the
// sector we want to read .
//移动文件指针到需要读取位置
SetFilePointer (hDevice,
(LogicalSector*512),
NULL,
FILE_BEGIN);
// reading sector(s) ...
//读数据
if (!ReadFile ( hDevice,
buffer,
512*numsec,
&bytesread,
NULL) )
{
/*
int err;
char error[10];
err=GetLastError ();
itoa (err, error, 10);
MessageBox (error, "Reading sectors ...Failed ");
return NULL ;
*/
}
//关闭
CloseHandle(hDevice);
return buffer ;
}
下面的代码演示了,如何读写A驱
/* -----------------------------------------------------
Read Floppy Disk Sector for win NT/2000
reads [numsec] sectors from [head] [track] [sector]
-------------------------------------------------------*/
char* ReadSectors(int head, int sector, int track, int numsec)
{
// getting logical sector from absolute head/track/sector ...
//计算扇区位置
int LogicalSector = (sector-1) +
(head*SECTORSPERTRACK) +
(track*SECTORSPERTRACK*NUMOFHEADS) ;
char *buffer ;
HANDLE hDevice ;
HANDLE hDevice;
char* buffer = (char*)malloc (512*numsec);
strset ( buffer , ' ');
DWORD bytesread ;
// getting a handle to the drive a: using
// CreateFile () function ....
//打开驱动器 //./A:
hDevice = CreateFile("////.//A:",
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == NULL)
{
MessageBox ("Failed !");
return NULL;
}
// setting the file pointer to the start of the
// sector we want to read .
//移动文件指针到需要读取位置
SetFilePointer (hDevice,
(LogicalSector*512),
NULL,
FILE_BEGIN);
// reading sector(s) ...
//读数据
if (!ReadFile ( hDevice,
buffer,
512*numsec,
&bytesread,
NULL) )
{
/*
int err;
char error[10];
err=GetLastError ();
itoa (err, error, 10);
MessageBox (error, "Reading sectors ...Failed ");
return NULL ;
*/
}
//关闭
CloseHandle(hDevice);
return buffer ;
}
- Win2000下直接读写磁盘扇区
- Win2000下直接读写磁盘扇区
- VC++实现Win2000下直接读写磁盘扇区
- VC++实现Win2000下直接读写磁盘扇区
- VC++实现Win2000下直接读写磁盘扇区
- VC++实现Win2000下直接读写磁盘扇区
- VC++实现Win2000下直接读写磁盘扇区
- WinNT平台下直接读写磁盘扇区
- 直接读写磁盘扇区
- 不同WINDOWS平台下磁盘逻辑扇区的直接读写
- VC++实现 Win200 0下直接读写磁盘扇区
- 不同WINDOWS平台下磁盘逻辑扇区的直接读写
- 不同WINDOWS平台下磁盘逻辑扇区的直接读写
- VC++实现Win200直接读写磁盘扇区
- 构造IRP 直接读写磁盘扇区内容
- [Win32] 直接读写磁盘扇区(磁盘绝对读写)
- [Win32] 直接读写磁盘扇区(磁盘绝对读写)
- WinCE系统下应用程序直接读写存储设备(U盘)磁盘扇区
- 国际形势充满变化 正确估价中国实力
- 长大了,变的现实了。
- java-在Java中操作Zip文件,压缩/解压
- Windows 常用命令 :(Zzz)
- 关于PHP中的引用传值或返回值总结(英文)
- Win2000下直接读写磁盘扇区
- java-多线程技术
- 又一个人离开
- 如何得到硬盘序列号?.NET版本[C#]
- 关于DateList一行绑定多个数据分页(一)cs文件
- Reading/Writing Disk Sectors (Absolute Disk Read/Write)
- What is PREROLL?
- Q.2931:ATM 信令用户接口--网络大典
- 关于DateList一行绑定多个数据分页(二)aspx文件