|
From: SD on 9 May 2008 01:56 Hi, I want to use raw read() to read and dump out contents of the sectors of a hard disk partition. I searched on the net but haven't found very useful links. I want to do this using just plain "C" without using any Win32 APIs. Appreciate if someone can point me to some links. TIA, SD
From: Alex Blekhman on 9 May 2008 04:37 "SD" wrote: > I want to use raw read() to read and dump out contents of the > sectors of a hard disk partition. I searched on the net but > haven't found very useful links. I want to do this using just > plain "C" without using any Win32 APIs. First of all, what do you mean by "plain C"? ANSI C? If it's the latter, then `read' is not plain C. The function `read' is deprecated and the standard conformant name is `_read'. On other words, you can't perfom such platform specific operation as reading the sectors of a hard disk partition in ANSI C. You will have to use platform specific API or vendor specific CRT extensions one way or another. Here's the program that reads 1MB of data from second hard disk in the system: <code> int main() { LPCTSTR pszDisk = _T("\\\\.\\PhysicalDrive1"); int d = _topen(pszDisk, _O_BINARY | _O_RDONLY); const SIZE_T n = 1024 * 1024; PBYTE buff = new BYTE[n](); int res = _read(d, buff, n); _close(d); if(res != -1) { // do something with the buffer // ... } delete[] buff; return 0; } </code> See more info about opening physical drives in MSDN article for `CreateFile' function. HTH Alex
|
Pages: 1 Prev: side-by-side info problem Next: how to use pointer to std::vector |