This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aguiar
Recipients aguiar
Date 2009-02-28.19:02:29
SpamBayes Score 9.9082945e-06
Marked as misclassified No
Message-id <1235847751.77.0.558509867366.issue5396@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-02-28 19:02:31aguiarsetrecipients: + aguiar
2009-02-28 19:02:31aguiarsetmessageid: <1235847751.77.0.558509867366.issue5396@psf.upfronthosting.co.za>
2009-02-28 19:02:30aguiarlinkissue5396 messages
2009-02-28 19:02:29aguiarcreate