Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Win32 Write RAW Physical Disk Python 3.3.2

878 views
Skip to first unread message

khanta

unread,
Feb 19, 2014, 7:42:02 AM2/19/14
to pytho...@python.org
Hello,
I am trying to write to the raw physical disk on Windows 8.1 but I
get an error:
PermissionError: [Errno 13] Permission denied: '\\\\.\\PHYSICALDRIVE2\\\\'

OS: Windows 8.1
Python: 3.3.2
Drive is a USB drive
Running as administrator

Code Snippet:

with open(r"\\.\PHYSICALDRIVE2\\", "rb+") as f: #Writing Binary!
f.seek(unallocatedoffset + 0)
f.write(t1)


or

with open('\\\\.\\PHYSICALDRIVE2\\', "rb+") as f: #Writing Binary!
f.seek(unallocatedoffset + 0)
f.write(t1)

or

f = os.fdopen(os.open('\\\\.\\PHYSICALDRIVE2\\' os.O_CREAT |
os.O_WRONLY | os.O_APPEND | os.O_EXCL))


Any suggestions? Is it possible?

Chris Angelico

unread,
Feb 19, 2014, 10:45:30 AM2/19/14
to pytho...@python.org
On Thu, Feb 20, 2014 at 2:44 AM, Chris Angelico <ros...@gmail.com> wrote:
> On Wed, Feb 19, 2014 at 11:42 PM, khanta <kha...@gmail.com> wrote:
>> PermissionError: [Errno 13] Permission denied: '\\\\.\\PHYSICALDRIVE2\\\\'
>
> Have you tried running your script as administrator? Raw writing to a
> disk quite possibly is (and definitely should be) a restricted action.

Whoops! I missed seeing that somehow. You already are. Sorry about that!

ChrisA

Chris Angelico

unread,
Feb 19, 2014, 10:44:56 AM2/19/14
to pytho...@python.org
On Wed, Feb 19, 2014 at 11:42 PM, khanta <kha...@gmail.com> wrote:
> PermissionError: [Errno 13] Permission denied: '\\\\.\\PHYSICALDRIVE2\\\\'

Have you tried running your script as administrator? Raw writing to a
disk quite possibly is (and definitely should be) a restricted action.

ChrisA

kha...@gmail.com

unread,
Feb 21, 2014, 4:32:35 PM2/21/14
to
Can anyone tell me if it is not possible? It would save me a lot of time.
Has anyone ever written to the raw disk on windows?

Mark Lawrence

unread,
Feb 21, 2014, 4:42:31 PM2/21/14
to pytho...@python.org
On 21/02/2014 21:32, kha...@gmail.com wrote:
> Can anyone tell me if it is not possible? It would save me a lot of time.
> Has anyone ever written to the raw disk on windows?
>

Sorry I can't help you, but you're more likely to get answers if you
didn't top post and you use a decent email client or follow the
instructions here https://wiki.python.org/moin/GoogleGroupsPython to
prevent us seeing double line spacing.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


Jerry Hill

unread,
Feb 21, 2014, 4:46:16 PM2/21/14
to python-list (General)
On Wed, Feb 19, 2014 at 7:42 AM, khanta <kha...@gmail.com> wrote:
> Hello,
> I am trying to write to the raw physical disk on Windows 8.1 but I
> get an error:
> PermissionError: [Errno 13] Permission denied: '\\\\.\\PHYSICALDRIVE2\\\\'

Is there a volume mounted from the drive at the time you're attempting
to write to the physical device? According to some MSDN documentation
(http://msdn.microsoft.com/en-us/library/aa365747%28VS.85%29.aspx ),
it doesn't look like you can write to a physical device if the sectors
you're attempting to write are mounted at the time. There appear to be
a lot of caveats. Take a look at the section of that page starting
with "If you write directly to a volume that has a mounted file
system, you must first obtain exclusive access to the volume." for
lots of details.

--
Jerry
0 new messages