I think the volume lock error message need to me more descriptive. Right now it just says "access denied". Most people aren't going to know what that means or what it's refering to.
I will look on to that. Under what circumstances you get volume lock error ? Because I haven't got that error yet. The error messages are provided by Windows itself, so I will have to catch this particular error and alter the message.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I do not know what caused it. It maybe a Windows issue. I had a 32GB SD that I was trying to backup. Win32DiskImager and dotNet Disk Imager both threw the same expection. win32DI's error message was more discriptive about it being a volume lock issue (I'm assuming they are catching the same exception just adding more to the error message). I tried restart the computer several times, and inserting the SD card and starting DiskImager and inserting the SD card in various differnet orders. I finally resolved it by putting it in another laptop, which didn't throw an error, backing it up then formating it and writting the image back on to the card.
First laptop was a Surface Book with Win 10 64bit, second laptop was a Dell Latitude 5420 with Win 10 32 bit.That's really all I can tell you. Card is a 32GB Class 10 kingston that came with the RPi3 CanaKit http://www.canakit.com/raspberry-pi-3-starter-kit.html.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I did some research about this issue, and I haven't found much information. It's really bad I can't replicate this issue, therefore debugging and resolving that is really hard. I've found only one thing that could be somehow interesting. Does your SD card have any filesystem ? MBR or GTP ? Or is it RAW ? It could be somehow related with filesystem on target drive. If it is RAW, try to create filesystem on SD card and retry.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
They are RPi images that I am working with so the first partion on the card has a fat file system. I assume the partition table is MBR. This last time I got the error message (that I screen shoted and posted below) was because my my card was corrupted. However the first time and what prompted this thread, there was nothing wrong with the card that I could tell, it booted fine.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
More descriptive error messages are implemented since version 0.7.235.18, but the error you mentioned is still there. Can you test it again, what error message you get ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, it is the same error as with Win32 Disk Imager... that means it must be Windows issue. Probably somehow bypassable, but since I can't replicate it, I don't know how to fix it.
I have released the source code with latest release, if you are familiar with C#, you may want to play with it. I somewhere read, that if you get access denied when locking device, the lock may not be even neccessary. You can try to comment it out and see what happens.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've released a new test build (HERE), it is suppressing error 5 when locking device and I would be delighted if you give it a try. I just need to warn you, it's at your own risk, using this tool is always a bit risky, so test it on SD cards with no data or backup first (with production version of dotNet Disk Imager).
Please let me know if you decide either way, to test it or not and if you decide to go for it, let me know what happened.
Thank you for your cooperation.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry I missed you reply about releasing the source, to many things going on at once. Yes I'm a C# dev so I'm pretty curious to peruse the source. I'll also try to give the new build a try. I'll need to see if I can re create the error again give my track record so far it shouldn't take long though.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, that's great. Hope you will find a solution and if you do, you will share it with us ;) Just a little warning, it is uncommented and really messy code. I've released it in this condition, because there were people asking for source code and I didn't want to keep it for myself until I've got some time. I've plans to clean it up and properly refactor, but as you said, too many more important things happening right now.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've only looked at it alittle so far. It's uncommented yes, but you and I have very different definitions of messy code. Your messy code is cleaner than my "clean" code. Guess I need to improve some. Also if I find a decent solution I let you know, and send you back patched source.
Last edit: TheColonel26 2016-11-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Great, thank you very much.
I would start around function "GetLockOnVolume" in "NativeDiskWrapper" class in "DiskAccess" namespace. As I've mentioned somewhere, I've read an opinion (guess it was on StackOverflow) if you get error 5 from locking the device, you may not even need to lock it, you should have exclusive access to device already. So try to alter the function as follows:
internalstaticboolGetLockOnVolume(IntPtrhandle){intbytesReturned=0;boolresult;result=NativeDisk.DeviceIoControl(handle,NativeDisk.FSCTL_LOCK_VOLUME,IntPtr.Zero,0,IntPtr.Zero,0,refbytesReturned,IntPtr.Zero);if(!result){varexception=newWin32Exception(Marshal.GetLastWin32Error());if(exception.NativeErrorCode==5){returntrue;}thrownewException(string.Format("Error occured when trying to get lock on volume.\nError code: {0}\nMessage: {1}",exception.NativeErrorCode,exception.Message));}returnresult;}
Thats exactly the same what I did in the "test build" posted above. But you could also debug it and so on.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just an FYI your test build with the lock check disabled works fine. If I get some time this weekend (20% chance of that) I plan on adding a warning when it happens and an option to proceed without lock. It also might be my imagination, but it seems that when it's not locked it writes faster. I'll need to run some tests to confirm this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Interesting information, thank you very much for your cooperation. Since you are second person to confirm that it works without lock I wouldn't even display warning about it. It may be more confusing than helpful/informational for the user. Even I wouldn't know what that means if I didn't do this research about it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I will look on to that. Under what circumstances you get volume lock error ? Because I haven't got that error yet. The error messages are provided by Windows itself, so I will have to catch this particular error and alter the message.
I do not know what caused it. It maybe a Windows issue. I had a 32GB SD that I was trying to backup. Win32DiskImager and dotNet Disk Imager both threw the same expection. win32DI's error message was more discriptive about it being a volume lock issue (I'm assuming they are catching the same exception just adding more to the error message). I tried restart the computer several times, and inserting the SD card and starting DiskImager and inserting the SD card in various differnet orders. I finally resolved it by putting it in another laptop, which didn't throw an error, backing it up then formating it and writting the image back on to the card.
First laptop was a Surface Book with Win 10 64bit, second laptop was a Dell Latitude 5420 with Win 10 32 bit.That's really all I can tell you. Card is a 32GB Class 10 kingston that came with the RPi3 CanaKit http://www.canakit.com/raspberry-pi-3-starter-kit.html.
I did some research about this issue, and I haven't found much information. It's really bad I can't replicate this issue, therefore debugging and resolving that is really hard. I've found only one thing that could be somehow interesting. Does your SD card have any filesystem ? MBR or GTP ? Or is it RAW ? It could be somehow related with filesystem on target drive. If it is RAW, try to create filesystem on SD card and retry.
They are RPi images that I am working with so the first partion on the card has a fat file system. I assume the partition table is MBR. This last time I got the error message (that I screen shoted and posted below) was because my my card was corrupted. However the first time and what prompted this thread, there was nothing wrong with the card that I could tell, it booted fine.
And now I am back to the first problem where nothing it wrong with it, it just won't lock for read.
More descriptive error messages are implemented since version 0.7.235.18, but the error you mentioned is still there. Can you test it again, what error message you get ?
Here is a screen shot
OK, it is the same error as with Win32 Disk Imager... that means it must be Windows issue. Probably somehow bypassable, but since I can't replicate it, I don't know how to fix it.
I have released the source code with latest release, if you are familiar with C#, you may want to play with it. I somewhere read, that if you get access denied when locking device, the lock may not be even neccessary. You can try to comment it out and see what happens.
I've released a new test build (HERE), it is suppressing error 5 when locking device and I would be delighted if you give it a try. I just need to warn you, it's at your own risk, using this tool is always a bit risky, so test it on SD cards with no data or backup first (with production version of dotNet Disk Imager).
Please let me know if you decide either way, to test it or not and if you decide to go for it, let me know what happened.
Thank you for your cooperation.
Sorry I missed you reply about releasing the source, to many things going on at once. Yes I'm a C# dev so I'm pretty curious to peruse the source. I'll also try to give the new build a try. I'll need to see if I can re create the error again give my track record so far it shouldn't take long though.
Ok, that's great. Hope you will find a solution and if you do, you will share it with us ;) Just a little warning, it is uncommented and really messy code. I've released it in this condition, because there were people asking for source code and I didn't want to keep it for myself until I've got some time. I've plans to clean it up and properly refactor, but as you said, too many more important things happening right now.
I've only looked at it alittle so far. It's uncommented yes, but you and I have very different definitions of messy code. Your messy code is cleaner than my "clean" code. Guess I need to improve some. Also if I find a decent solution I let you know, and send you back patched source.
Last edit: TheColonel26 2016-11-15
Great, thank you very much.
I would start around function "GetLockOnVolume" in "NativeDiskWrapper" class in "DiskAccess" namespace. As I've mentioned somewhere, I've read an opinion (guess it was on StackOverflow) if you get error 5 from locking the device, you may not even need to lock it, you should have exclusive access to device already. So try to alter the function as follows:
Thats exactly the same what I did in the "test build" posted above. But you could also debug it and so on.
Just an FYI your test build with the lock check disabled works fine. If I get some time this weekend (20% chance of that) I plan on adding a warning when it happens and an option to proceed without lock. It also might be my imagination, but it seems that when it's not locked it writes faster. I'll need to run some tests to confirm this.
Interesting information, thank you very much for your cooperation. Since you are second person to confirm that it works without lock I wouldn't even display warning about it. It may be more confusing than helpful/informational for the user. Even I wouldn't know what that means if I didn't do this research about it.
Well in that case, I won't bother with writing code for a warning. Works for me.