def do_fallocate(filename: str, size: int):
log.debug('Fallocating %s for size %d.', filename, size)
fd = os.open(filename, os.O_RDWR)
try:
# os.posix_fallocate:
# 1. does not support FALLOC_FL_KEEP_SIZE
# 2. has bug: http://bugs.python.org/issue31106
# 3. will emulate instead of raising of error if operation is not
# supported (see libc docs on posix_fallocate)
fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, size)
except OSError as err:
if err.errno != errno.EOPNOTSUPP:
raise
log.warning('Fallocate is not supported on your FS. Skipped.')
finally:
os.close(fd)
评论列表
文章目录