I am using python to directly access the bytes written on a compact flash card. With windows (the OS I am currently using) a drive can be accessed directly by adding a '\\\\.\\' (\\.\ when printed) before the drive name. The result is a string like '\\\\.\\G:'. Opening and writing these drives work fine; But after some of my code executes o.close() and o.seek() both fail.
f=open("\\\\.\\G:",'rb+') # use 'rb+' for disk/drive/card writing
f.seek(512*3) # multiples of 512 are required (here seek works fine)
f.write(512*b'x') # fill sector with the letter x
... # some of my code
f.close() # Errorno 22 : invalid argument
f.seek(0) # Also an errorno 22, even if file is open
This suggests the problem is in my other code.... However that code only uses the file to seek and write, which using those functions there causes no errors.
Here is my exact error message:
Traceback (most recent call last):
File "NFS.py", line 139 in <module>
make_fs(args.input, fo)
File "NFS.py", line 12 in make_fs
root_data, ls=walk(i, o, tmp)
File "NFS.py", line 34 in walk
o.seek(512*i)
OSError: [Errorno 22] Invalid argument
Why would python (or the OS) give me 'invalid argument' when seeking to zero or closing the file? Remember, of course, that the file is really a hardware compact flash card.