* fhandler.h (class fhandler_dev_raw): Add private member `varblkop'
to be set when variable blocksize mode is on. * fhandler_raw.cc: Eliminate `\n' from trace output. (clear): Set `varblkop' to 0. (dup): Copy varblkop as well. (writebuf): Care for variable blocksize. (open): Ditto. (raw_read): Ditto. (raw_write): Ditto. * fhandler_tape.cc (open): Ditto. (ioctl): Ditto. Some cleanups.
This commit is contained in:
parent
20b9d598ea
commit
c49b9c439c
|
@ -1,3 +1,17 @@
|
|||
Sun Jul 23 20:00:00 2000 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* fhandler.h (class fhandler_dev_raw): Add private member `varblkop'
|
||||
to be set when variable blocksize mode is on.
|
||||
* fhandler_raw.cc: Eliminate `\n' from trace output.
|
||||
(clear): Set `varblkop' to 0.
|
||||
(dup): Copy varblkop as well.
|
||||
(writebuf): Care for variable blocksize.
|
||||
(open): Ditto.
|
||||
(raw_read): Ditto.
|
||||
(raw_write): Ditto.
|
||||
* fhandler_tape.cc (open): Ditto.
|
||||
(ioctl): Ditto. Some cleanups.
|
||||
|
||||
Sat Jul 22 18:40:00 2000 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
Patch suggested by Kazuhiro Fujieda <fujieda@jaist.ac.jp>.
|
||||
|
|
|
@ -359,6 +359,7 @@ protected:
|
|||
int lastblk_to_read : 1;
|
||||
int is_writing : 1;
|
||||
int has_written : 1;
|
||||
int varblkop : 1;
|
||||
int unit;
|
||||
|
||||
virtual void clear (void);
|
||||
|
|
|
@ -37,7 +37,7 @@ static BOOL write_file (HANDLE fh, const void *buf, DWORD to_write,
|
|||
*err = GetLastError ();
|
||||
}
|
||||
}
|
||||
syscall_printf ("%d (err %d) = WriteFile (%d, %d, write %d, written %d, 0)\n",
|
||||
syscall_printf ("%d (err %d) = WriteFile (%d, %d, write %d, written %d, 0)",
|
||||
ret, *err, fh, buf, to_write, *written);
|
||||
return ret;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ static BOOL read_file (HANDLE fh, void *buf, DWORD to_read,
|
|||
*err = GetLastError ();
|
||||
}
|
||||
}
|
||||
syscall_printf ("%d (err %d) = ReadFile (%d, %d, to_read %d, read %d, 0)\n",
|
||||
syscall_printf ("%d (err %d) = ReadFile (%d, %d, to_read %d, read %d, 0)",
|
||||
ret, *err, fh, buf, to_read, *read);
|
||||
return ret;
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ fhandler_dev_raw::clear (void)
|
|||
eom_detected = 0;
|
||||
eof_detected = 0;
|
||||
lastblk_to_read = 0;
|
||||
varblkop = 0;
|
||||
unit = 0;
|
||||
}
|
||||
|
||||
|
@ -87,15 +88,19 @@ fhandler_dev_raw::writebuf (void)
|
|||
|
||||
if (is_writing && devbuf && devbufend)
|
||||
{
|
||||
memset (devbuf + devbufend, 0, devbufsiz - devbufend);
|
||||
DWORD to_write = ((devbufend - 1) / 512 + 1) * 512;
|
||||
ret = 0;
|
||||
DWORD to_write;
|
||||
int ret = 0;
|
||||
|
||||
if (!write_file (get_handle (), devbuf, to_write, &written, &ret))
|
||||
{
|
||||
if (is_eom (ret))
|
||||
memset (devbuf + devbufend, 0, devbufsiz - devbufend);
|
||||
if (get_device () != FH_TAPE)
|
||||
to_write = ((devbufend - 1) / 512 + 1) * 512;
|
||||
else if (varblkop)
|
||||
to_write = devbufend;
|
||||
else
|
||||
to_write = devbufsiz;
|
||||
if (!write_file (get_handle (), devbuf, to_write, &written, &ret)
|
||||
&& is_eom (ret))
|
||||
eom_detected = 1;
|
||||
}
|
||||
if (written)
|
||||
has_written = 1;
|
||||
devbufstart = devbufend = 0;
|
||||
|
@ -142,14 +147,10 @@ fhandler_dev_raw::open (const char *path, int flags, mode_t)
|
|||
if (ret)
|
||||
{
|
||||
if (devbufsiz > 1L)
|
||||
{
|
||||
devbuf = new char[devbufsiz];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
devbufsiz = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -219,7 +220,7 @@ fhandler_dev_raw::raw_read (void *ptr, size_t ulen)
|
|||
if (devbufstart < devbufend)
|
||||
{
|
||||
bytes_to_read = min (len, devbufend - devbufstart);
|
||||
debug_printf ("read %d bytes from buffer (rest %d)\n",
|
||||
debug_printf ("read %d bytes from buffer (rest %d)",
|
||||
bytes_to_read, devbufstart - devbufend);
|
||||
memcpy (ptr, devbuf + devbufstart, bytes_to_read);
|
||||
len -= bytes_to_read;
|
||||
|
@ -235,18 +236,23 @@ fhandler_dev_raw::raw_read (void *ptr, size_t ulen)
|
|||
}
|
||||
if (len > 0)
|
||||
{
|
||||
if (len >= devbufsiz)
|
||||
if (!varblkop && len >= devbufsiz)
|
||||
{
|
||||
if (get_device () == FH_TAPE)
|
||||
bytes_to_read = (len / devbufsiz) * devbufsiz;
|
||||
else
|
||||
bytes_to_read = (len / 512) * 512;
|
||||
tgt = (char *) ptr;
|
||||
debug_printf ("read %d bytes direct from file\n",
|
||||
bytes_to_read);
|
||||
debug_printf ("read %d bytes direct from file",bytes_to_read);
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes_to_read = devbufsiz;
|
||||
tgt = devbuf;
|
||||
debug_printf ("read %d bytes from file into buffer\n",
|
||||
if (varblkop)
|
||||
debug_printf ("read variable bytes from file into buffer");
|
||||
else
|
||||
debug_printf ("read %d bytes from file into buffer",
|
||||
bytes_to_read);
|
||||
}
|
||||
if (!read_file (get_handle (), tgt, bytes_to_read, &read2, &ret))
|
||||
|
@ -342,7 +348,8 @@ fhandler_dev_raw::raw_write (const void *ptr, size_t len)
|
|||
{
|
||||
while (len > 0)
|
||||
{
|
||||
if ((len < devbufsiz || devbufend > 0) && devbufend < devbufsiz)
|
||||
if (!varblkop &&
|
||||
(len < devbufsiz || devbufend > 0) && devbufend < devbufsiz)
|
||||
{
|
||||
bytes_to_write = min (len, devbufsiz - devbufend);
|
||||
memcpy (devbuf + devbufend, p, bytes_to_write);
|
||||
|
@ -353,7 +360,12 @@ fhandler_dev_raw::raw_write (const void *ptr, size_t len)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (devbufend == devbufsiz)
|
||||
if (varblkop)
|
||||
{
|
||||
bytes_to_write = len;
|
||||
tgt = p;
|
||||
}
|
||||
else if (devbufend == devbufsiz)
|
||||
{
|
||||
bytes_to_write = devbufsiz;
|
||||
tgt = devbuf;
|
||||
|
@ -449,6 +461,7 @@ fhandler_dev_raw::dup (fhandler_base *child)
|
|||
fhc->eom_detected = eom_detected;
|
||||
fhc->eof_detected = eof_detected;
|
||||
fhc->lastblk_to_read = lastblk_to_read;
|
||||
fhc->varblkop = varblkop;
|
||||
fhc->unit = unit;
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -77,22 +77,21 @@ fhandler_dev_tape::open (const char *path, int flags, mode_t)
|
|||
struct mtpos pos;
|
||||
|
||||
if (! ioctl (MTIOCGET, &get))
|
||||
{
|
||||
/* Tape drive supports and is set to variable block size. */
|
||||
if (get.mt_dsreg == 0)
|
||||
devbufsiz = get.mt_maxblksize;
|
||||
else
|
||||
devbufsiz = get.mt_dsreg;
|
||||
}
|
||||
varblkop = get.mt_dsreg == 0;
|
||||
|
||||
if (devbufsiz > 1L)
|
||||
{
|
||||
devbuf = new char [ devbufsiz ];
|
||||
}
|
||||
|
||||
/*
|
||||
* The following rewind in position 0 solves a problem which appears
|
||||
/* The following rewind in position 0 solves a problem which appears
|
||||
* in case of multi volume archives: The last ReadFile on first medium
|
||||
* returns ERROR_NO_DATA_DETECTED. After media change, all subsequent
|
||||
* ReadFile calls return ERROR_NO_DATA_DETECTED, too!
|
||||
* The call to tape_set_pos seems to reset some internal flags!
|
||||
*/
|
||||
* ReadFile calls return ERROR_NO_DATA_DETECTED, too.
|
||||
* The call to tape_set_pos seems to reset some internal flags. */
|
||||
if ((! ioctl (MTIOCPOS, &pos)) && (! pos.mt_blkno))
|
||||
{
|
||||
op.mt_op = MTREW;
|
||||
|
@ -280,14 +279,9 @@ fhandler_dev_tape::ioctl (unsigned int cmd, void *buf)
|
|||
break;
|
||||
case MTRETEN:
|
||||
if (! tape_get_feature (TAPE_DRIVE_END_OF_DATA))
|
||||
{
|
||||
ret = ERROR_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
if (! (ret = tape_set_pos (TAPE_REWIND, 0, FALSE)))
|
||||
{
|
||||
else if (! (ret = tape_set_pos (TAPE_REWIND, 0, FALSE)))
|
||||
ret = tape_prepare (TAPE_TENSION);
|
||||
}
|
||||
break;
|
||||
case MTBSFM:
|
||||
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, -op->mt_count, TRUE);
|
||||
|
@ -297,13 +291,9 @@ fhandler_dev_tape::ioctl (unsigned int cmd, void *buf)
|
|||
break;
|
||||
case MTEOM:
|
||||
if (tape_get_feature (TAPE_DRIVE_END_OF_DATA))
|
||||
{
|
||||
ret = tape_set_pos (TAPE_SPACE_END_OF_DATA, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, 32767);
|
||||
}
|
||||
break;
|
||||
case MTERASE:
|
||||
ret = tape_erase (TAPE_ERASE_SHORT);
|
||||
|
@ -324,27 +314,43 @@ fhandler_dev_tape::ioctl (unsigned int cmd, void *buf)
|
|||
}
|
||||
ret = tape_get_blocksize (&min, NULL, &max, NULL);
|
||||
if (ret)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (op->mt_count < min || op->mt_count > max)
|
||||
{
|
||||
ret = ERROR_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
if (devbuf && (size_t) op->mt_count == devbufsiz)
|
||||
if (devbuf && (size_t) op->mt_count == devbufsiz && !varblkop)
|
||||
{
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
if (devbuf && (size_t) op->mt_count < devbufend - devbufstart)
|
||||
if ((op->mt_count == 0
|
||||
&& !tape_get_feature (TAPE_DRIVE_VARIABLE_BLOCK))
|
||||
|| (op->mt_count > 0
|
||||
&& (op->mt_count < min || op->mt_count > max)))
|
||||
{
|
||||
ret = ERROR_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
if (devbuf && op->mt_count > 0
|
||||
&& (size_t) op->mt_count < devbufend - devbufstart)
|
||||
{
|
||||
ret = ERROR_MORE_DATA;
|
||||
break;
|
||||
}
|
||||
if (! (ret = tape_set_blocksize (op->mt_count)))
|
||||
{
|
||||
char *buf = new char [ op->mt_count ];
|
||||
size_t size = 0;
|
||||
if (op->mt_count == 0)
|
||||
{
|
||||
struct mtget get;
|
||||
if ((ret = tape_status (&get)) != NO_ERROR)
|
||||
break;
|
||||
size = get.mt_maxblksize;
|
||||
ret = NO_ERROR;
|
||||
}
|
||||
char *buf = new char [ size ];
|
||||
if (!buf)
|
||||
{
|
||||
ret = ERROR_OUTOFMEMORY;
|
||||
break;
|
||||
}
|
||||
if (devbuf)
|
||||
{
|
||||
memcpy(buf,devbuf + devbufstart, devbufend - devbufstart);
|
||||
|
@ -352,12 +358,11 @@ fhandler_dev_tape::ioctl (unsigned int cmd, void *buf)
|
|||
delete [] devbuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
devbufend = 0;
|
||||
}
|
||||
devbufstart = 0;
|
||||
devbuf = buf;
|
||||
devbufsiz = op->mt_count;
|
||||
devbufsiz = size;
|
||||
varblkop = op->mt_count == 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue