[issue5396] os.read not handling O_DIRECT flag

Eduardo Aguiar report at bugs.python.org
Sat Feb 28 20:02:31 CET 2009


New submission from Eduardo Aguiar <aguiar at users.sourceforge.net>:

At posixmodule.c (line 6306)

static PyObject *
posix_read(PyObject *self, PyObject *args)
{
	int fd, size, n;
	PyObject *buffer;
	if (!PyArg_ParseTuple(args, "ii:read", &fd, &size))
		return NULL;
	if (size < 0) {
		errno = EINVAL;
		return posix_error();
	}
	buffer = PyString_FromStringAndSize((char *)NULL, size);
	if (buffer == NULL)
		return NULL;
	Py_BEGIN_ALLOW_THREADS
	n = read(fd, PyString_AsString(buffer), size);
	Py_END_ALLOW_THREADS
	if (n < 0) {
		Py_DECREF(buffer);
		return posix_error();
	}
	if (n != size)
		_PyString_Resize(&buffer, n);
	return buffer;
}

os.read does not work with O_DIRECT flag. It fails with errno = EINVAL.

>From read(2) man page:

       EINVAL fd  is attached to an object which is unsuitable for
reading; or
              the file was opened with  the  O_DIRECT  flag,  and 
either  the
              address  specified  in buf, the value specified in count,
or the
              current file offset is not suitably aligned.

if os.open is called with O_DIRECT flag enabled, the buffer used in
"read" must be page aligned and "size" must be multiple of pagesize also.

----------
components: Library (Lib)
messages: 82938
nosy: aguiar
severity: normal
status: open
title: os.read not handling O_DIRECT flag
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5396>
_______________________________________


More information about the Python-bugs-list mailing list