* 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.
This commit is contained in:
parent
2c9cefa586
commit
c74e68b7e2
|
@ -1,3 +1,10 @@
|
||||||
|
2012-10-16 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
2012-10-15 Christopher Faylor <me.cygwin2012@cgf.cx>
|
2012-10-15 Christopher Faylor <me.cygwin2012@cgf.cx>
|
||||||
|
|
||||||
* fhandler_tty.cc (fhandler_pty_slave::write): Fix potential exit from
|
* fhandler_tty.cc (fhandler_pty_slave::write): Fix potential exit from
|
||||||
|
|
|
@ -668,24 +668,27 @@ _off64_t
|
||||||
fhandler_dev_floppy::lseek (_off64_t offset, int whence)
|
fhandler_dev_floppy::lseek (_off64_t offset, int whence)
|
||||||
{
|
{
|
||||||
char buf[bytes_per_sector];
|
char buf[bytes_per_sector];
|
||||||
_off64_t lloffset = offset;
|
|
||||||
_off64_t current_pos = (_off64_t) -1;
|
_off64_t current_pos = (_off64_t) -1;
|
||||||
LARGE_INTEGER sector_aligned_offset;
|
LARGE_INTEGER sector_aligned_offset;
|
||||||
size_t bytes_left;
|
size_t bytes_left;
|
||||||
|
|
||||||
if (whence == SEEK_END)
|
if (whence == SEEK_END)
|
||||||
{
|
{
|
||||||
lloffset += drive_size;
|
offset += drive_size;
|
||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
}
|
}
|
||||||
else if (whence == SEEK_CUR)
|
else if (whence == SEEK_CUR)
|
||||||
{
|
{
|
||||||
current_pos = get_current_position ();
|
current_pos = get_current_position ();
|
||||||
lloffset += current_pos - (devbufend - devbufstart);
|
_off64_t exact_pos = current_pos - (devbufend - devbufstart);
|
||||||
|
/* Shortcut when used to get current position. */
|
||||||
|
if (offset == 0)
|
||||||
|
return exact_pos;
|
||||||
|
offset += exact_pos;
|
||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whence != SEEK_SET || lloffset < 0 || lloffset > drive_size)
|
if (whence != SEEK_SET || offset < 0 || offset > drive_size)
|
||||||
{
|
{
|
||||||
set_errno (EINVAL);
|
set_errno (EINVAL);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -696,15 +699,15 @@ fhandler_dev_floppy::lseek (_off64_t offset, int whence)
|
||||||
{
|
{
|
||||||
if (current_pos == (_off64_t) -1)
|
if (current_pos == (_off64_t) -1)
|
||||||
current_pos = get_current_position ();
|
current_pos = get_current_position ();
|
||||||
if (current_pos - devbufend <= lloffset && lloffset <= current_pos)
|
if (current_pos - devbufend <= offset && offset <= current_pos)
|
||||||
{
|
{
|
||||||
devbufstart = devbufend - (current_pos - lloffset);
|
devbufstart = devbufend - (current_pos - offset);
|
||||||
return lloffset;
|
return offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sector_aligned_offset.QuadPart = rounddown (lloffset, bytes_per_sector);
|
sector_aligned_offset.QuadPart = rounddown (offset, bytes_per_sector);
|
||||||
bytes_left = lloffset - sector_aligned_offset.QuadPart;
|
bytes_left = offset - sector_aligned_offset.QuadPart;
|
||||||
|
|
||||||
/* Invalidate buffer. */
|
/* Invalidate buffer. */
|
||||||
devbufstart = devbufend = 0;
|
devbufstart = devbufend = 0;
|
||||||
|
@ -779,17 +782,6 @@ fhandler_dev_floppy::ioctl (unsigned int cmd, void *buf)
|
||||||
debug_printf ("BLKALIGNOFF");
|
debug_printf ("BLKALIGNOFF");
|
||||||
*(int *)buf = 0;
|
*(int *)buf = 0;
|
||||||
break;
|
break;
|
||||||
case RDSETBLK:
|
|
||||||
/* Just check the restriction that blocksize must be a multiple
|
|
||||||
of the sector size of the underlying volume sector size,
|
|
||||||
then fall through to fhandler_dev_raw::ioctl. */
|
|
||||||
debug_printf ("RDSETBLK");
|
|
||||||
if (((struct rdop *) buf)->rd_parm % bytes_per_sector)
|
|
||||||
{
|
|
||||||
set_errno (EINVAL);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/*FALLTHRU*/
|
|
||||||
default:
|
default:
|
||||||
ret = fhandler_dev_raw::ioctl (cmd, buf);
|
ret = fhandler_dev_raw::ioctl (cmd, buf);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "winsup.h"
|
#include "winsup.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include <cygwin/rdevio.h>
|
#include <cygwin/rdevio.h>
|
||||||
#include <sys/mtio.h>
|
#include <sys/mtio.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
@ -151,36 +152,32 @@ fhandler_dev_raw::ioctl (unsigned int cmd, void *buf)
|
||||||
mop.mt_count = op->rd_parm;
|
mop.mt_count = op->rd_parm;
|
||||||
ret = ioctl (MTIOCTOP, &mop);
|
ret = ioctl (MTIOCTOP, &mop);
|
||||||
}
|
}
|
||||||
else if ((devbuf && ((op->rd_parm <= 1 && (devbufend - devbufstart))
|
else if ((op->rd_parm <= 1 && get_major () != DEV_TAPE_MAJOR)
|
||||||
|| op->rd_parm < devbufend - devbufstart))
|
|| (op->rd_parm > 1 && (op->rd_parm % devbufalign))
|
||||||
|| (op->rd_parm > 1 && (op->rd_parm % 512))
|
|
||||||
|| (get_flags () & O_DIRECT))
|
|| (get_flags () & O_DIRECT))
|
||||||
/* The conditions for a *valid* parameter are these:
|
/* The conditions for a valid parameter are:
|
||||||
- If there's still data in the current buffer, it must
|
- The new size is either 0 or 1, both indicating unbuffered
|
||||||
fit in the new buffer.
|
I/O, and the device is a tape device.
|
||||||
- The new size is either 0 or 1, both indicating unbufferd
|
- Or, the new buffersize must be a multiple of the
|
||||||
I/O, or the new buffersize must be a multiple of 512.
|
required buffer alignment.
|
||||||
- In the O_DIRECT case, the whole request is invalid. */
|
- In the O_DIRECT case, the whole request is invalid. */
|
||||||
ret = ERROR_INVALID_PARAMETER;
|
ret = ERROR_INVALID_PARAMETER;
|
||||||
else if (!devbuf || op->rd_parm != devbufsiz)
|
else if (!devbuf || op->rd_parm != devbufsiz)
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
_off64_t curpos = lseek (0, SEEK_CUR);
|
||||||
|
|
||||||
if (op->rd_parm > 1L)
|
if (op->rd_parm > 1L)
|
||||||
buf = new char [op->rd_parm];
|
buf = new char [op->rd_parm + devbufalign];
|
||||||
if (buf && devbufsiz > 1L)
|
|
||||||
{
|
|
||||||
memcpy (buf, devbuf + devbufstart, devbufend - devbufstart);
|
|
||||||
devbufend -= devbufstart;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
devbufend = 0;
|
|
||||||
|
|
||||||
if (devbufsiz > 1L)
|
if (devbufsiz > 1L)
|
||||||
delete [] devbufalloc;
|
delete [] devbufalloc;
|
||||||
|
|
||||||
devbufstart = 0;
|
devbufalloc = buf;
|
||||||
devbuf = buf;
|
devbuf = (char *) roundup2 ((uintptr_t) buf, devbufalign);
|
||||||
devbufsiz = op->rd_parm ?: 1L;
|
devbufsiz = op->rd_parm ?: 1L;
|
||||||
|
devbufstart = devbufend = 0;
|
||||||
|
lseek (curpos, SEEK_SET);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue