tags:

views:

79

answers:

1

I googled a lot and I couldn't find any answer to this problem...

I have a C++ console application that reads a 1GB SD card that fixes improperly closed files and writes the FAT table accordingly. The SD card is written at the beginning by a firmware in a custom made device. It worked OK up to Xp and stopped working in Win Vista/seven. I tried elevating privileges: within an administrator account type, I launched a cmd window using the "run as administrator" method but no luck. I also tried with a manifest asking for highestAvailable privileges but no luck.

I read in some post that “Windows Vista doesn't allow you to access the disks from user-mode processes at all. Does anybody know about any way of bypassing this behavior?

I’m working in a workaround however I would like to know if this is impossible or not

Edit:

This is my first post here so I don't quite understand about the linking issue... But I'm not reated to any spam at all... just asking in a comunity driven site :)

The code looks like

hDevice = CreateFile(buffer,GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,NULL, OPEN_EXISTING,0,NULL); 

I then read the BTB information from the SD and look for and improperly closed file.

Finally when trying to write to the SD

WriteFile(hDevice,buffer,SD_SECTOR_SIZE, &temp, 0)

I get an Access denied (error #5)

The string on CreateFile() is \.\g: as the g letter correspond to the SD card on my machine. All that works ok and as I said before it woks on XP. I also tried using: DeviceIoControl with FSCTL_LOCK_VOLUME but that gives a mem fault error.

Hope this helps to understand and thanks for any help

+2  A: 

I think this is due to the path string "buffer"; I ran into the same issue. The path you are using to get device access needs to look lik this "\\.\PhysicalDrive%d" %d is the decimal number of the drive.

From Vista on this string is CASE SENSITIVE. Check the spelling. You also need admin rights, just as before in XP.

For Volumes,. the letter needs to CAPITALIZED e.g. "\\.\G:"

Also note that it is much better to access the SD card as a device rathern than the volume, since if Windows mounts it, there might be a file system mounted with a write cache.

Furthermore: I forgot to mention that the buffer your read/write the data to/from should be page aligned and the read a multiple of the sector size. VirtualAlloc() does this

Dominik Weber
Thanks Balpha for your edits!Thanks Dominik for your answer :)I think the syntax for the lpFileName in CreateFile always starts with \\.\ as noted in http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspxIt seems that capitalizing the volume letter doesn't help at all in my case.I also tried \\.\PhysicalDriveXX (XX being 1 in my case) but later on ReadFile(hDevice,inf_buffer,SD_SECTOR_SIZE, returns nothing in inf_buffer but an empty one. However CreateFile is not complaining at all. This last test performed under debugging on XP with ms vc++6 (dev machine)
andy
Thanks andy - the path I've entered had two slashes, but the slash is an escape char, so you actually have to enter four to get two. I've also remembered the bit about the buffer alignment.If you can open the file the name and permissions are correct, if the read fails, it's buffer size/alignment and/or "locking".I think the locking is more important when you want to write.
Dominik Weber