reply for BC_Programmer :
With that in mind, use 0 (exclusive access)...
I probably should have done this, but my first inclination was to try to
co-exist with any other things wanting access.
explicitly lock the volume using DeviceIoControl()
i did not think of this. although when i have the boot sector open,
how much real traffic should there be to that sector ? it is no
real surprise that it only showed up when i rebooted. the same can
not be said about other sectors though, so i guess i should do the
locking bit. also this was originally to be mainly for the dvd rom,
so locking was not really an issue, since i did not plan any writing.
lets not drag the dvd into this, by the way ; it has its own quirks,
some i am still figuring out, and if we start on that, this will become
the thread that never dies.
Writes/reads have to be aligned on sector boundaries ...
buffer a multiple of the sector size.
i did these, at least as far as i could tell. i used DeviceIoControl
rather than GetDiskFreeSpace to get the disk and sector size. i wonder
if they might be disagreeing with each other ?
checking the literature, my buffer address probably is not alligned in
memory to a sector boundry. seems like if this was part of the problem,
it would either give back bad data, or not work, like it does when not
sector alligned. although i might try and fix this later and see if it
crashes again, now that i know what to do about it when it won't boot.
"it really doesn't matter what real sector i am in"
if you want to write to the boot sector, I would imagine that is rather important.
what i meant was, for instance if i go to the start of the disk, and it shows me
the boot sector consistantly, i don't care if some drive logic is really showing
me some sector in the middle where it remapped the sector to because the real
start sector had an error. if the OS thinks it is at sector 0, and presents me
with the boot sector, thats good enough for me. if the thing was not handling all
the junk like sectors starting at 1, chs or lba, and similar, it would not be
working at all. and microsoft would be telling me to use something diffrent.
Also, direct physical access goes past the actual Filesystem driver, which may
also be relevant
some stuff may be bypassed with this method, but there must still be a good hunk
of the filesystem between me and the drive. part of the design philosophy was
to be able to treat EVERYTHING like a file, at least with this part if the API.
personally i'd rather have drive specific API calls.
You are trying to deal with a co-operative, pre-emptive, protected mode Operating System
I know, that is one reason i did not go with exclusive access.
NTFS keeps a backup of the boot sector.
I know, although i have yet to locate it. it's position varies depending on the
specific OS. I don't think this is a factor here ; it seems to have failed
during the bios sector loading. if bios was aware of an alternate boot sector
copy, it should have used it, and I'd never have known my main sector was bad.
I suspect that bios us unaware of the copy and it is there for use by the OS,
probably for fixboot, and similar. and it possibly might have come into play
if it had booted, and the OS saw the odball boot sector ; but it never made
it that far.
Also, the symptoms you describe are usually caused by a corrupt MBR.
i agree, but as i said, i kept looking at it and it kept looking ok. both the
before and after reads of the data looked identical.
Since the first instance ... caused by your application, I don't see any reason
to think that the second write ... was more successful.
It was just as successful - both failed. and that is what told me boot up was
failing before running the boot sector code. as to why, since the OS ( when
running ) and my app see the data just like it should be, i did not suspect
my stupid app was the cause. why the data can read and look ok with the OS,
but not by the bios loader, is still unanswered. and you would think the bios
would display a message or beep or something when it hit a problem.
Consider comparing what your application sees with what DSKPROBE
i would love to. part of the problem is DSKPROBE won't show me any physical
drives to select. I don't know if it is a quirk in DSKPROBE, or more likely,
of my system. for that matter, if DSKPROBE had worked, i would not be writing
this thing in the first place.
or maybe i might still have done it just to do it. i won't be really happy,
until i can do ANYTHING with this system, although typically, everyone else
will probably be running windows 47 ( or Win 2047, depending on the marketing
guys ) on organic computers by that time.
---------------------------------------------------------------------
reply for Geek-9pm :
http://thestarman.pcministry.com/asm/mbr/BootToolsRefs.htm
neat link. I'm going to try some of the stuff from it. a lot of it looks like
the sort of things i like to play with.