delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/03/06/03:22:49

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Originating-IP: [203.61.170.42]
X-Originating-Email: [jasonwinter AT hotmail DOT com]
X-Sender: jasonwinter AT hotmail DOT com
From: "Jason Winter" <jasonwinter AT hotmail DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: read(): varblk tape records...(& Fix for : read())
Date: Sat, 06 Mar 2004 08:20:59 +0000
Mime-Version: 1.0
Message-ID: <Sea2-F40WgP1A83xiDd00066c52@hotmail.com>
X-OriginalArrivalTime: 06 Mar 2004 08:20:59.0870 (UTC) FILETIME=[F4DFE7E0:01C40353]

------=_NextPart_000_2718_65ad_1a40
Content-Type: text/plain; format=flowed

Hi Corinna,

When you do get a working tape drive, here is an example of read making the 
next write 'go bad'...

Fixed Blocks... which I don't use...  (Use a parameter on testtape.exe to 
test both cases.)
Jason.
ps. Why did it get a protection-fault? maybe it's the cygwin1.dll snapshot, 
but I only get it with *that* example where the API is failing.

_________________________________________________________________
What's your house worth? Click here to find out:  
http://www.ninemsn.realestate.com.au

------=_NextPart_000_2718_65ad_1a40
Content-Type: text/plain; name="FBWERR.TXT"; format=flowed
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="FBWERR.TXT"

run1: fixed-block, with 'proper' reads of block-length
c:\testtape

Opening Tape Handle
stblk.mt_blkno=0
ST0: Status: 41030000 BOT ON-LINE
Setting length 512 records. rc=0
ST0: Status: 41030000 BOT ON-LINE
rewind... rc=0
ST0: Status: 41030000 BOT ON-LINE
write... rc=512, errno=0
ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=1
backspace... rc=0
ST0: Status: 41030000 BOT ON-LINE
stblk.mt_blkno=0
read... rc=512, errno=0
AC23456789
ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=1
write... rc=512, errno=0
ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=2
backspace... rc=0
ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=1
read... rc=512, errno=0
BD23456789
ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=2
rewind... rc=0
ST0: Status: 41030000 BOT ON-LINE
Closing Tape Handle

run2: with first-read only reading 1 character:
c:\testtape read1

Opening Tape Handle
stblk.mt_blkno=0
ST0: Status: 41030000 BOT ON-LINE
Setting length 512 records. rc=0
ST0: Status: 41030000 BOT ON-LINE
rewind... rc=0
ST0: Status: 41030000 BOT ON-LINE
write... rc=512, errno=0
ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=1
backspace... rc=0
ST0: Status: 41030000 BOT ON-LINE
stblk.mt_blkno=0
read1... rc=1, errno=0
A
ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=1
write... rc=512, errno=0
ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=2
backspace... rc=0
ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=1
read... rc=-1, errno=28

ST0: Status: 01030000 ON-LINE
stblk.mt_blkno=2
rewind... rc=0
ST0: Status: 41030000 BOT ON-LINE
Closing Tape Handle
      9 [main] testtape 102 handle_exceptions: Exception: 
STATUS_ACCESS_VIOLATION
   6056 [main] testtape 102 open_stackdumpfile: Dumping stack trace to 
testtape.exe.stackdump



------=_NextPart_000_2718_65ad_1a40
Content-Type: text/plain; name="testtape.c"; format=flowed
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="testtape.c"

//#include <io.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mtio.h>

int fh;
struct mtget stblk;
struct mtop  opblk;

#define BLKLEN 512
#define RBLKLEN 512
//#define RBLKLEN 65535 // var blks only

char buf [BLKLEN] = "0123456789";

void disp_stat () {
    int  stat;
    char buf [256];

    ioctl (fh, MTIOCGET, (char*)&stblk);
    stat = stblk.mt_gstat;

    /* Display tape status */
    sprintf (buf, "Status: %8.8X", stat);
    if (GMT_EOF(stat)) strcat (buf, " EOF");
    if (GMT_BOT(stat)) strcat (buf, " BOT");
    if (GMT_EOT(stat)) strcat (buf, " EOT");
    if (GMT_SM(stat)) strcat (buf, " SET-MARK");
    if (GMT_EOD(stat)) strcat (buf, " EOD");
    if (GMT_WR_PROT(stat)) strcat (buf, " WR-PROT");
    if (GMT_ONLINE(stat)) strcat (buf, " ON-LINE");
    if (GMT_D_6250(stat)) strcat (buf, " 6250");
    if (GMT_D_1600(stat)) strcat (buf, " 1600");
    if (GMT_D_800(stat)) strcat (buf, " 800");
    if (GMT_DR_OPEN(stat)) strcat (buf, " NO-TAPE");

    printf ("ST0: %s\n", buf);
};

void common () {
    printf ("stblk.mt_blkno=%d\n", stblk.mt_blkno);
};

void set_blk (int len) {
    int rc;

    if (len)
        printf ("Setting length %d records.", len);
    else
        printf ("Setting variable records.");
    fflush (stdout);

    opblk.mt_op = MTSETBLK;
    opblk.mt_count = len;
    rc = ioctl (fh, MTIOCTOP, (char*)&opblk);

    printf (" rc=%d\n", rc);
};

void my_read (int fh) {
    int rc;
    int en;
    char buf2 [RBLKLEN];

    printf ("read...");
    fflush (stdout);
    memset (buf2, ' ', 10);

    errno = 0;
    rc = read (fh, buf2, RBLKLEN);
    en = errno;

    printf (" rc=%d, errno=%d\n", rc, en);
    buf2 [10] = 0;
    printf ("%s\n", buf2);
    disp_stat ();
    common ();
};

void my_read1 (int fh) {
    int rc;
    int en;
    char buf2 [1];

    printf ("read1...");
    fflush (stdout);
    memset (buf2, ' ', 10);

    errno = 0;
    rc = read (fh, buf2, 1);
    en = errno;

    printf (" rc=%d, errno=%d\n", rc, en);
    buf2 [1] = 0;
    printf ("%s\n", buf2);
    disp_stat ();
    common ();
};

void my_write (int fh) {
    int rc;
    int en;

    printf ("write...");
    fflush (stdout);

    errno = 0;
    rc = write (fh, buf, BLKLEN);
    en = errno;

    printf (" rc=%d, errno=%d\n", rc, en);
    disp_stat ();
    common ();
};

void my_bksp (int fh) {
    int rc;

    printf ("backspace...");
    fflush (stdout);
    opblk.mt_op = MTBSR;
    opblk.mt_count = 1;
    rc = ioctl (fh, MTIOCTOP, (char*)&opblk);
    printf (" rc=%d\n", rc);
    disp_stat ();
    common ();
};

void my_rew (int fh) {
    int rc;

    printf ("rewind...");
    fflush (stdout);
    opblk.mt_op = MTREW;
    opblk.mt_count = 1;
    rc = ioctl (fh, MTIOCTOP, (char*)&opblk);
    printf (" rc=%d\n", rc);
    disp_stat ();
};

int main (int argc) {
    int rc;

    printf ("Opening Tape Handle\n");

    fh = open ("/dev/st0", O_RDWR);
    if (fh >= 0) {

        rc = ioctl (fh, MTIOCGET, (char*)&stblk);
        if (rc < 0) {
            printf ("Failed to IOCTL the Tape\n");
        } else {
            common ();
        };

        disp_stat ();
        set_blk (BLKLEN);
        disp_stat ();
        my_rew (fh);

        buf [0] = 'A';
        buf [1] = 'C';
        my_write (fh);
        my_bksp (fh);

        if (argc == 1)
            my_read (fh);
        else
            my_read1 (fh); // special 1 char read

        buf [0] = 'B';
        buf [1] = 'D';
        my_write (fh);
        my_bksp (fh);
        my_read (fh);
        my_rew (fh);

        printf ("Closing Tape Handle\n");
        close (fh);

    } else {

        printf ("Failed to Open Tape\n");
    };

    return (0);
};



------=_NextPart_000_2718_65ad_1a40
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------=_NextPart_000_2718_65ad_1a40--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019