summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler_raw.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2012-10-16 09:52:26 +0000
committerCorinna Vinschen <corinna@vinschen.de>2012-10-16 09:52:26 +0000
commitc74e68b7e298ddeafdb2db81b9473e9648a493f4 (patch)
treebf90287d02e55157d1283118445c8d8f2547dc8c /winsup/cygwin/fhandler_raw.cc
parent2c9cefa5868fce3417e19058a41a541a2baaf076 (diff)
downloadcygnal-c74e68b7e298ddeafdb2db81b9473e9648a493f4.tar.gz
cygnal-c74e68b7e298ddeafdb2db81b9473e9648a493f4.tar.bz2
cygnal-c74e68b7e298ddeafdb2db81b9473e9648a493f4.zip
* fhandler_floppy.cc (fhandler_dev_floppy::lseek): Remove lloffset.
Use offset directly. Add shortcut for lseek(fd, 0, SEEK_CUR) case. (fhandler_dev_floppy::ioctl): Drop wrong RDSETBLK case. * fhandler_raw.cc (fhandler_dev_raw::ioctl): Revamp RDSETBLK code.
Diffstat (limited to 'winsup/cygwin/fhandler_raw.cc')
-rw-r--r--winsup/cygwin/fhandler_raw.cc33
1 files changed, 15 insertions, 18 deletions
diff --git a/winsup/cygwin/fhandler_raw.cc b/winsup/cygwin/fhandler_raw.cc
index 61981a4da..cb8829559 100644
--- a/winsup/cygwin/fhandler_raw.cc
+++ b/winsup/cygwin/fhandler_raw.cc
@@ -11,6 +11,7 @@
#include "winsup.h"
+#include <unistd.h>
#include <cygwin/rdevio.h>
#include <sys/mtio.h>
#include <sys/param.h>
@@ -151,36 +152,32 @@ fhandler_dev_raw::ioctl (unsigned int cmd, void *buf)
mop.mt_count = op->rd_parm;
ret = ioctl (MTIOCTOP, &mop);
}
- else if ((devbuf && ((op->rd_parm <= 1 && (devbufend - devbufstart))
- || op->rd_parm < devbufend - devbufstart))
- || (op->rd_parm > 1 && (op->rd_parm % 512))
+ else if ((op->rd_parm <= 1 && get_major () != DEV_TAPE_MAJOR)
+ || (op->rd_parm > 1 && (op->rd_parm % devbufalign))
|| (get_flags () & O_DIRECT))
- /* The conditions for a *valid* parameter are these:
- - If there's still data in the current buffer, it must
- fit in the new buffer.
- - The new size is either 0 or 1, both indicating unbufferd
- I/O, or the new buffersize must be a multiple of 512.
+ /* The conditions for a valid parameter are:
+ - The new size is either 0 or 1, both indicating unbuffered
+ I/O, and the device is a tape device.
+ - Or, the new buffersize must be a multiple of the
+ required buffer alignment.
- In the O_DIRECT case, the whole request is invalid. */
ret = ERROR_INVALID_PARAMETER;
else if (!devbuf || op->rd_parm != devbufsiz)
{
char *buf = NULL;
+ _off64_t curpos = lseek (0, SEEK_CUR);
+
if (op->rd_parm > 1L)
- buf = new char [op->rd_parm];
- if (buf && devbufsiz > 1L)
- {
- memcpy (buf, devbuf + devbufstart, devbufend - devbufstart);
- devbufend -= devbufstart;
- }
- else
- devbufend = 0;
+ buf = new char [op->rd_parm + devbufalign];
if (devbufsiz > 1L)
delete [] devbufalloc;
- devbufstart = 0;
- devbuf = buf;
+ devbufalloc = buf;
+ devbuf = (char *) roundup2 ((uintptr_t) buf, devbufalign);
devbufsiz = op->rd_parm ?: 1L;
+ devbufstart = devbufend = 0;
+ lseek (curpos, SEEK_SET);
}
break;
default: