I'm trying to convert the following code from linux to windows...
I was wondering if someone could point out the best way to approach this. I was messing with DeviceIOControl, but I'm having problems working out the commands, possibly way off track with that call, so if you can help, thankyou thank you thankyou...
/* setmax.c - aeb, 000326 - use on 2.4.0test9 or newer */
/* IBM part thanks to Matan Ziv-Av <matan@svgalib.org> */
/*
* Results on Maxtor disks:
* The jumper that clips capacity does not influence the value returned
* by READ_NATIVE_MAX_ADDRESS, so it is possible to set the jumper
* and let the kernel, or a utility (like this one) run at boot time
* restore full capacity.
* For example, run "setmax -d 0 /dev/hdX" for suitable X.
* Kernel patches exist that do the same.
*
* Results on IBM disks:
* The jumper that clips capacity is ruthless. You clipped capacity.
* However, if your BIOS hangs on a large disk, do not use the jumper
* but find another machine and use a utility (like this one) to
* clip the non-volatile max address.
* For example, run "setmax -m 66055248 /dev/hdX" for suitable X.
* Now go back to your first machine and proceed as with Maxtor drives above.
*/
#include <stdio.h>
#include <fcntl.h>
#include <getopt.h>
#include <linux/hdreg.h>
/*
* result: in LBA mode precisely what is expected
* in CHS mode the correct H and S, and C mod 65536.
*/
unsigned int
get_native_max(int fd, int slave) {
unsigned char args[7];
int i, max;
/*
* SET_MAX_ADDRESS requires immediately preceding READ_NATIVE_MAX_ADDRESS
*
* On old Maxtor disk: this fails for delta <= 254, succeeds for delta >= 255.
* (So, in order to get the last 255*512=130560 bytes back one has to reboot.
* Side effect: reset to CurCHS=16383/16/63, CurSects=16514064.)
* On new Maxtor disk: this works.
* On IBM disk without jumper: this works.
*/
void
set_max_address(int fd, int slave, int delta, int max, int volat) {
unsigned char args[7];
int i, nativemax, newmax;
static char *usage_txt =
"Call: setmax [-d D] [-m M] DEVICE\n"
"\n"
"The call \"setmax --max M DEVICE\" will do a SET_MAX command\n"
"to set the non-volatile max number of accessible sectors to M.\n"
"\n"
"The call \"setmax --delta D DEVICE\" will do a SET_MAX command\n"
"to set the maximum accessible sector number D sectors\n"
"below end-of-disk.\n"
"\n"
"The call \"setmax DEVICE\" will do a READ_NATIVE_MAX_ADDRESS\n"
"command, and report the maximum accessible sector number.\n"
"\n"
"This is IDE-only. Probably DEVICE is /dev/hdx for some x.\n\n";
main(int argc, char **argv){
int fd, c;
int delta, max, volat;
/* If you modify device, also update slave, if necessary. */
/* The kernel already does this for us since 2.4.0test9. */
/* master: hda, hdc, hde; slave: hdb, hdd, hdf */
char *device = NULL; /* e.g. "/dev/hda" */
int slave = 0;
delta = max = volat = -1;
while ((c = getopt_long (argc, argv, short_opts, long_opts, NULL)) != -1) {
switch(c) {
case 'd':
delta = atoi(optarg);
volat = 1;
break;
case 'm':
max = atoi(optarg);
volat = 0;
break;
case '?':
default:
fprintf(stderr, "unknown option\n");
fprintf(stderr, usage_txt);
exit(1);
}
}
if (optind < argc)
device = argv[optind];
if (!device) {
fprintf(stderr, "no device specified - "
"use e.g. \"setmax /dev/hdb\"\n");
fprintf(stderr, usage_txt);
exit(1);
}
printf("Using device %s\n", device);
Bookmarks