* 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:
Corinna Vinschen 2000-07-23 19:33:44 +00:00
parent 20b9d598ea
commit c49b9c439c
4 changed files with 98 additions and 65 deletions

View File

@ -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> Sat Jul 22 18:40:00 2000 Corinna Vinschen <corinna@vinschen.de>
Patch suggested by Kazuhiro Fujieda <fujieda@jaist.ac.jp>. Patch suggested by Kazuhiro Fujieda <fujieda@jaist.ac.jp>.

View File

@ -359,6 +359,7 @@ protected:
int lastblk_to_read : 1; int lastblk_to_read : 1;
int is_writing : 1; int is_writing : 1;
int has_written : 1; int has_written : 1;
int varblkop : 1;
int unit; int unit;
virtual void clear (void); virtual void clear (void);

View File

@ -37,7 +37,7 @@ static BOOL write_file (HANDLE fh, const void *buf, DWORD to_write,
*err = GetLastError (); *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); ret, *err, fh, buf, to_write, *written);
return ret; return ret;
} }
@ -58,7 +58,7 @@ static BOOL read_file (HANDLE fh, void *buf, DWORD to_read,
*err = GetLastError (); *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); ret, *err, fh, buf, to_read, *read);
return ret; return ret;
} }
@ -76,6 +76,7 @@ fhandler_dev_raw::clear (void)
eom_detected = 0; eom_detected = 0;
eof_detected = 0; eof_detected = 0;
lastblk_to_read = 0; lastblk_to_read = 0;
varblkop = 0;
unit = 0; unit = 0;
} }
@ -87,15 +88,19 @@ fhandler_dev_raw::writebuf (void)
if (is_writing && devbuf && devbufend) if (is_writing && devbuf && devbufend)
{ {
memset (devbuf + devbufend, 0, devbufsiz - devbufend); DWORD to_write;
DWORD to_write = ((devbufend - 1) / 512 + 1) * 512; int ret = 0;
ret = 0;
if (!write_file (get_handle (), devbuf, to_write, &written, &ret)) memset (devbuf + devbufend, 0, devbufsiz - devbufend);
{ if (get_device () != FH_TAPE)
if (is_eom (ret)) to_write = ((devbufend - 1) / 512 + 1) * 512;
eom_detected = 1; 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) if (written)
has_written = 1; has_written = 1;
devbufstart = devbufend = 0; devbufstart = devbufend = 0;
@ -142,14 +147,10 @@ fhandler_dev_raw::open (const char *path, int flags, mode_t)
if (ret) if (ret)
{ {
if (devbufsiz > 1L) if (devbufsiz > 1L)
{ devbuf = new char[devbufsiz];
devbuf = new char[devbufsiz];
}
} }
else else
{ devbufsiz = 0;
devbufsiz = 0;
}
return ret; return ret;
} }
@ -219,7 +220,7 @@ fhandler_dev_raw::raw_read (void *ptr, size_t ulen)
if (devbufstart < devbufend) if (devbufstart < devbufend)
{ {
bytes_to_read = min (len, devbufend - devbufstart); 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); bytes_to_read, devbufstart - devbufend);
memcpy (ptr, devbuf + devbufstart, bytes_to_read); memcpy (ptr, devbuf + devbufstart, bytes_to_read);
len -= bytes_to_read; len -= bytes_to_read;
@ -235,19 +236,24 @@ fhandler_dev_raw::raw_read (void *ptr, size_t ulen)
} }
if (len > 0) if (len > 0)
{ {
if (len >= devbufsiz) if (!varblkop && len >= devbufsiz)
{ {
bytes_to_read = (len / 512) * 512; if (get_device () == FH_TAPE)
bytes_to_read = (len / devbufsiz) * devbufsiz;
else
bytes_to_read = (len / 512) * 512;
tgt = (char *) ptr; tgt = (char *) ptr;
debug_printf ("read %d bytes direct from file\n", debug_printf ("read %d bytes direct from file",bytes_to_read);
bytes_to_read);
} }
else else
{ {
bytes_to_read = devbufsiz; bytes_to_read = devbufsiz;
tgt = devbuf; tgt = devbuf;
debug_printf ("read %d bytes from file into buffer\n", if (varblkop)
bytes_to_read); 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)) 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) 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); bytes_to_write = min (len, devbufsiz - devbufend);
memcpy (devbuf + devbufend, p, bytes_to_write); memcpy (devbuf + devbufend, p, bytes_to_write);
@ -353,7 +360,12 @@ fhandler_dev_raw::raw_write (const void *ptr, size_t len)
} }
else else
{ {
if (devbufend == devbufsiz) if (varblkop)
{
bytes_to_write = len;
tgt = p;
}
else if (devbufend == devbufsiz)
{ {
bytes_to_write = devbufsiz; bytes_to_write = devbufsiz;
tgt = devbuf; tgt = devbuf;
@ -449,6 +461,7 @@ fhandler_dev_raw::dup (fhandler_base *child)
fhc->eom_detected = eom_detected; fhc->eom_detected = eom_detected;
fhc->eof_detected = eof_detected; fhc->eof_detected = eof_detected;
fhc->lastblk_to_read = lastblk_to_read; fhc->lastblk_to_read = lastblk_to_read;
fhc->varblkop = varblkop;
fhc->unit = unit; fhc->unit = unit;
} }
return ret; return ret;

View File

@ -77,22 +77,21 @@ fhandler_dev_tape::open (const char *path, int flags, mode_t)
struct mtpos pos; struct mtpos pos;
if (! ioctl (MTIOCGET, &get)) 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; devbufsiz = get.mt_dsreg;
} varblkop = get.mt_dsreg == 0;
if (devbufsiz > 1L) if (devbufsiz > 1L)
{ devbuf = new char [ devbufsiz ];
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 * in case of multi volume archives: The last ReadFile on first medium
* returns ERROR_NO_DATA_DETECTED. After media change, all subsequent * returns ERROR_NO_DATA_DETECTED. After media change, all subsequent
* ReadFile calls return ERROR_NO_DATA_DETECTED, too! * ReadFile calls return ERROR_NO_DATA_DETECTED, too.
* The call to tape_set_pos seems to reset some internal flags! * The call to tape_set_pos seems to reset some internal flags. */
*/
if ((! ioctl (MTIOCPOS, &pos)) && (! pos.mt_blkno)) if ((! ioctl (MTIOCPOS, &pos)) && (! pos.mt_blkno))
{ {
op.mt_op = MTREW; op.mt_op = MTREW;
@ -280,14 +279,9 @@ fhandler_dev_tape::ioctl (unsigned int cmd, void *buf)
break; break;
case MTRETEN: case MTRETEN:
if (! tape_get_feature (TAPE_DRIVE_END_OF_DATA)) if (! tape_get_feature (TAPE_DRIVE_END_OF_DATA))
{ ret = ERROR_INVALID_PARAMETER;
ret = ERROR_INVALID_PARAMETER; else if (! (ret = tape_set_pos (TAPE_REWIND, 0, FALSE)))
break; ret = tape_prepare (TAPE_TENSION);
}
if (! (ret = tape_set_pos (TAPE_REWIND, 0, FALSE)))
{
ret = tape_prepare (TAPE_TENSION);
}
break; break;
case MTBSFM: case MTBSFM:
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, -op->mt_count, TRUE); 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; break;
case MTEOM: case MTEOM:
if (tape_get_feature (TAPE_DRIVE_END_OF_DATA)) if (tape_get_feature (TAPE_DRIVE_END_OF_DATA))
{ ret = tape_set_pos (TAPE_SPACE_END_OF_DATA, 0);
ret = tape_set_pos (TAPE_SPACE_END_OF_DATA, 0);
}
else else
{ ret = tape_set_pos (TAPE_SPACE_FILEMARKS, 32767);
ret = tape_set_pos (TAPE_SPACE_FILEMARKS, 32767);
}
break; break;
case MTERASE: case MTERASE:
ret = tape_erase (TAPE_ERASE_SHORT); 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); ret = tape_get_blocksize (&min, NULL, &max, NULL);
if (ret) if (ret)
{
break; break;
} if (devbuf && (size_t) op->mt_count == devbufsiz && !varblkop)
if (op->mt_count < min || op->mt_count > max)
{
ret = ERROR_INVALID_PARAMETER;
break;
}
if (devbuf && (size_t) op->mt_count == devbufsiz)
{ {
ret = 0; ret = 0;
break; 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; ret = ERROR_INVALID_PARAMETER;
break; 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))) 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) if (devbuf)
{ {
memcpy(buf,devbuf + devbufstart, devbufend - devbufstart); memcpy(buf,devbuf + devbufstart, devbufend - devbufstart);
@ -352,12 +358,11 @@ fhandler_dev_tape::ioctl (unsigned int cmd, void *buf)
delete [] devbuf; delete [] devbuf;
} }
else else
{ devbufend = 0;
devbufend = 0; devbufstart = 0;
} devbuf = buf;
devbufstart = 0; devbufsiz = size;
devbuf = buf; varblkop = op->mt_count == 0;
devbufsiz = op->mt_count;
} }
} }
break; break;