简体   繁体   English

用fstream原始读取启动扇区

[英]Raw read the boot sector with fstream

fstream file("G:", ios::in | ios::binary);

unsigned char buffer[512];

file.read((char *)buffer, 512);

file.close();

cout << buffer <<"\n";

I want to raw read the boot sector from my flash drive. 我想从闪存驱动器中原始读取启动扇区。 Can i use for this job fstream? 我可以使用此工作流吗?

File stream operations are written to access files . 文件流操作被写入以访问文件 The CPP Reference does not further specify what a 'file' is in this context -- and maybe they are right. CPP参考未进一步指定“文件”在这种情况下的含义,也许它们是正确的。 After all, it highly depends on the OS what's considered a 'file'. 毕竟, 高度依赖于操作系统的“文件”。

However: under none of these interpretations is the boot sector a file. 但是:在所有这些解释中,引导扇区都不是文件。 You cannot see or read the boot sector in Windows Explorer or OS X Finder -- it's "above and beyond" the level of files . 您无法在Windows资源管理器或OS X Finder中看到或读取引导扇区-它在文件级别之上。

Your test program fails because "G:" is not interpreted as 'a flash drive', but merely as 'a full path specification'. 您的测试程序失败,因为“ G:”不解释为“闪存驱动器”,而只是解释为“完整路径规范”。 When working on the level of "boot sectors", there are no paths and drive letter assignments. 在“引导扇区”的水平工作时, 没有路径和驱动器盘符分配。 You are working with physical objects instead: actual disks, and actual sectors. 您正在使用物理对象:实际的磁盘和实际的扇区。

See http://www.codeproject.com/Articles/28314/Reading-and-Writing-to-Raw-Disk-Sectors for a first taste of raw reading. 请参阅http://www.codeproject.com/Articles/28314/Reading-and-Writing-to-Raw-Disk-Sectors ,以了解原始阅读的初衷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM