hello everyone. i read about the functions abswrite() or absread() etc, but these fucntions are not supported in modern compilers. i would like to know what are the modern alternatives of these functions in c++?? btw i am using visual studio 2010 and rad studio xe.

Dani AI

Generated

A short practical summary (for and anyone who wants sector-level disk I/O):

absread/abswrite were DOS/Borland-era helpers that invoked DOS interrupts to read/write raw sectors; they do not exist in modern Windows toolchains because modern OSes protect disks and no longer expose DOS interrupts. See the historical Borland library reference for how those functions worked. (1library.net)

On Windows the supported approach is to use the Win32 storage APIs: open the physical disk or a volume with CreateFile (use names like \\\\.\\PhysicalDrive0 or \\\\.\\C: and OPEN_EXISTING), query geometry with DeviceIoControl (for example IOCTL_DISK_GET_DRIVE_GEOMETRY_EX), then position with SetFilePointerEx and use ReadFile / WriteFile for the actual I/O. The CreateFile and device IOCTL docs explain required flags and privileges. (learn.microsoft.com)

Example sketch (concept only — follow the docs before running anything that can destroy data):

HANDLE h = CreateFileA("\\\\.\\PhysicalDrive0",
                      GENERIC_READ|GENERIC_WRITE,
                      FILE_SHARE_READ|FILE_SHARE_WRITE,
                      NULL, OPEN_EXISTING,
                      FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH,
                      NULL);

SetFilePointerEx(h, sectorIndex * bytesPerSector, NULL, FILE_BEGIN);
ReadFile(h, buffer, bytesPerSector, &bytesRead, NULL);

Practical gotchas and safety notes: you must run elevated (administrator), and unbuffered/noncached I/O imposes strict rules — offsets and lengths must be multiples of the volume physical sector size and buffers must be properly aligned (use VirtualAlloc or aligned allocations). To access the very last sectors of a mounted volume you may need to call FSCTL_ALLOW_EXTENDED_DASD_IO via DeviceIoControl. Raw writes can corrupt the filesystem; test on images or removable media first. (learn.microsoft.com)

If the goal is learning rather than building a production tool, work against a disk image file (a single file you control) or a virtual disk in a VM — that avoids most of the permissions and safety risks while you experiment.

Recommended Answers

All 5 Replies

What are you trying to do where you need these functions?

What do you need those functions for? Are you modernizing a virus? ;)

not really. viruses are a far far huge thing. i just wanna have some power to read and write directly at the disk on basis of sectors and tracks etc.

i just wanna have some power to read and write directly at the disk on basis of sectors and tracks etc.

My initial reaction is "Why do you want to do that?". But it's not as if the Windows API doesn't provide low level device support:


http://msdn.microsoft.com/en-us/library/aa363858%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/aa363219%28v=vs.85%29.aspx

It's just that need for that kind of support is fairly rare. Let's just say I'm interested in what you're doing because it sounds intriguing. :) It's not often that people ask how to read and write hard disk geometry on this forum.

ahan :) i would like to learn much more than that. btw i need some advice if u dont mind. i am a student of computer science, i have gained basic skills of c++ and all that. made some text mode games that look and feel great (upto my level) if u wanna check here is the link http://adf.ly/19013/space .. the thing is that should i go for web programming or should i go for .net?? i dont find web programming much interesting. i love to program with c++ but i wanna move on? is it the right time to jump to c#? if so what books shouls i consult? thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.