Query size of block device file in Python

Posted by ??O????? on Stack Overflow See other posts from Stack Overflow or by ??O?????
Published on 2010-05-05T13:30:51Z Indexed on 2010/05/05 14:38 UTC
Read the original article Hit count: 296

Filed under:
|
|
|

Hello.

I have a Python script that reads a file (typically from optical media) marking the unreadable sectors, to allow a re-attempt to read said unreadable sectors on a different optical reader.

I discovered that my script does not work with block devices (e.g. /dev/sr0), in order to create a copy of the contained ISO9660/UDF filesystem, because os.stat().st_size is zero. The algorithm currently needs to know the filesize in advance; I can change that, but the issue (of knowing the block device size) remains, and it's not answered here, so I open this question.

I am aware of the following two related SO questions:

Therefore, I'm asking: in Python, how can I get the file size of a block device file?

© Stack Overflow or respective owner

Related posts about python

Related posts about linux