File holes in Linux
lists at cheimes.de
Wed Sep 29 22:32:05 CEST 2010
Am 29.09.2010 11:05, schrieb Tom Potts:
> A quick `ls -sl filehole.test' will show that the created file actually
> takes up about 980k, rather than the 0 bytes expected.
> If anyone can let me know if this is indeed a bug or feature request, how to
> get around it, or where to take it next, I'd really appreciate it.
It's not a bug in Python. You simply misunderstand how sparse files are
created. When you write null bytes to a file each null byte takes up
space on the file system, too. In order to create a hole, you have to
set the file handler's position beyond the file's end.
>>> with open("sparse", "w") as fh:
$ ls -l --si sparse
-rw-r--r-- 1 heimes heimes 1,1G 2010-09-29 22:25 sparse
$ ls -s sparse
$ du sparse
More information about the Python-list