Discussion:
//./d: and writes
(too old to reply)
Les Cargill
2012-07-17 17:43:21 UTC
Permalink
I am using the Mingw toolchain. I also reproduced this using Tcl version
8.6. O/S is WinXP or Win7.

So I would like to write a utility to recover a USB stick
that has been formatted to FAT32 which has had sector 0 erased or
all zeros ( erased would be all ones ). IOW, it just happened to
fail when it was removed without being unmounted.

When I use fopen() to open D: as a raw device (path "//./d:") , it fails
because of permissions.

FILE *f=fopen("//./d:","wb");

What's the best way to do what I am trying to do? Are there
raw ioctl() or "give me more privilege" calls I can use to
do this? Are the ioctl() calls similar to Unix?

There is a verison of "dd" for Windows here:
http://www.chrysocome.net/dd

dd does this just fine. IOW, I can overwrite the first sector
using dd, but I'd like to have a single executable do this for
purely arbitrary reasons.

Thanks in advance.

--
Les Cargill
JJ
2012-07-18 08:57:44 UTC
Permalink
Post by Les Cargill
I am using the Mingw toolchain. I also reproduced this using Tcl
version 8.6. O/S is WinXP or Win7.
So I would like to write a utility to recover a USB stick
that has been formatted to FAT32 which has had sector 0 erased
or all zeros ( erased would be all ones ). IOW, it just happened
to fail when it was removed without being unmounted.
When I use fopen() to open D: as a raw device (path "//./d:") , it fails
because of permissions.
FILE *f=fopen("//./d:","wb");
What's the best way to do what I am trying to do? Are there
raw ioctl() or "give me more privilege" calls I can use to
do this? Are the ioctl() calls similar to Unix?
http://www.chrysocome.net/dd
dd does this just fine. IOW, I can overwrite the first sector
using dd, but I'd like to have a single executable do this for
purely arbitrary reasons.
Disk and volume access need the correct file sharing mode. fopen
isn't applicable for this, so use sopen instead. The open mode can
be any combination of read/write or both to open an existing file
(not as an empty/new file). The sharing mode must not deny anything
(i.e.: allow all access).

dd is an open source software, so you might want do download its
source code to learn how it works. Preferably the one from mingw
website since there might be Windows patches applied.
Les Cargill
2012-07-18 23:03:28 UTC
Permalink
Post by JJ
Post by Les Cargill
I am using the Mingw toolchain. I also reproduced this using Tcl
version 8.6. O/S is WinXP or Win7.
So I would like to write a utility to recover a USB stick
that has been formatted to FAT32 which has had sector 0 erased
or all zeros ( erased would be all ones ). IOW, it just happened
to fail when it was removed without being unmounted.
When I use fopen() to open D: as a raw device (path "//./d:") , it fails
because of permissions.
FILE *f=fopen("//./d:","wb");
What's the best way to do what I am trying to do? Are there
raw ioctl() or "give me more privilege" calls I can use to
do this? Are the ioctl() calls similar to Unix?
http://www.chrysocome.net/dd
dd does this just fine. IOW, I can overwrite the first sector
using dd, but I'd like to have a single executable do this for
purely arbitrary reasons.
Disk and volume access need the correct file sharing mode. fopen
isn't applicable for this, so use sopen instead.
What I found is that just plain old "open()" will also work.
Post by JJ
The open mode can
be any combination of read/write or both to open an existing file
(not as an empty/new file). The sharing mode must not deny anything
(i.e.: allow all access).
dd is an open source software, so you might want do download its
source code to learn how it works. Preferably the one from mingw
website since there might be Windows patches applied.
Right right.

--
Les Cargill

Loading...