VC、Linux、vxWorks读写物理扇区小结
来源:互联网 发布:刘雯怎么培养气质知乎 编辑:程序博客网 时间:2024/06/07 03:17
直接上程序:
1. Windows下的VC:
- HANDLE hDevice = CreateFile("\\\\.\\I:", GENERIC_READ|GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, OPEN_EXISTING, 0, NULL
- );
- if (hDevice == INVALID_HANDLE_VALUE)
- {
- printf("打开磁盘错误\n");
- return 0;
- }
- //读扇区
- DWORD bytesread = 0;
- unsigned char Buffer[1000] = {0};
- int SectorNumber=0;
- //for (int SectorNumber=0; SectorNumber<100; SectorNumber++)
- {
- SetFilePointer (hDevice, SectorNumber*512, 0, FILE_BEGIN);
- ReadFile (hDevice, Buffer, 512, &bytesread, NULL);
- getch();
- }
- //写操作
- memset(Buffer, 0x35, 512);
- SetFilePointer (hDevice, SectorNumber*512, 0, FILE_BEGIN);
- WriteFile (hDevice, Buffer, 512, &bytesread, NULL);
上面的CreateFile函数的第一个参数,是C: ,D:类似的盘符
2. vxWorks读扇区:参考mkboot.c源程序得到
- char lbaSectorZero[1024] = {0};
- int line, j;
- ATA_RAW ataRaw = {0};
- ataRaw.cylinder = 0;
- ataRaw.head = 0;
- ataRaw.sector = 1;
- ataRaw.pBuf = (char *)lbaSectorZero;
- ataRaw.nSecs = 1;
- ataRaw.direction = O_RDONLY;
- ataRawio (0, 0, &ataRaw);
- for(line=0; line<32; line++)
- {
- for(j=0; j<16; j++)
- {
- printf("%02x ", (unsigned char)lbaSectorZero[line*16+j]);
- }
- printf("\n");
- }
ataRawio.direction为0时是读,为1时是写,其他参考 target/h/drv/hdisk/ataDrv.h的ATA_RAW定义。
3. Linux:下面的/dev/sde,是U盘插上去后显示的设备符合:
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <linux/fs.h>
- #include <sys/ioctl.h>
- /*
- *
- */
- int main(int argc, char** argv)
- {
- int fd=0;
- int sizes = 0;
- char buf[1000] = {0};
- int line, j;
- fd = open("/dev/sde", O_RDONLY);
- if(fd !=-1)
- {
- ioctl(fd, BLKSSZGET, &sizes);
- printf("sector size=%d\n", sizes);
- lseek(fd, 0, SEEK_SET);
- read(fd, buf, sizes);
- for(line=0; line<32; line++)
- {
- for(j=0; j<16; j++)
- {
- printf("%02x ", (unsigned char)buf[line*16+j]);
- }
- printf("\n");
- }
- }
- return (EXIT_SUCCESS);
- }
阅读全文
0 0
- VC、Linux、vxWorks读写物理扇区小结
- VC、Linux、vxWorks读写物理扇区小结
- Linux中如何读写硬盘上指定物理扇区
- Linux中如何读写硬盘上指定物理扇区
- linux 读写磁盘扇区
- vc读写扇区资源搜集
- WinCE下的物理扇区读写
- Windows物理磁盘扇区读写示例总结
- Linux中如何读写硬盘(或Virtual Disk)上指定物理扇区
- VC++实现Win200直接读写磁盘扇区
- linux 下得到磁盘物理扇区大小
- windows NT/2000读写物理,逻辑磁盘扇区
- Linux下按扇区读写块设备
- Linux读写物理内存
- linux 物理内存读写
- VC++实现Win2000下直接读写磁盘扇区
- VC++实现Win2000下直接读写磁盘扇区
- VC++实现Win2000下直接读写磁盘扇区
- Spring DataSource的配置总结
- 钉钉解决ios返回键的问题
- [LeetCode]104. Maximum Depth of Binary Tree
- python学习(二十)
- react-native实现百度地图的实时导航
- VC、Linux、vxWorks读写物理扇区小结
- HTML代码中文在网页中乱码问题
- Java_冒泡、插入、快速、选择排序
- Codeforces-837D:Round Subset(DP)
- 决策树(Decision Tree)Demo
- C语言——宏定义及保留n位小数
- TNS-12547: TNS:lost contact解决办法
- lua.c:80:31: fatal error: readline/readline.h: No such file or directory
- php语言的cmpp协议应用