delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/03/04/19:44:22

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
Delivered-To: corinna-cygwin AT cygwin DOT com
X-Originating-IP: [210.84.179.229]
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
Cc: corinna-cygwin AT cygwin DOT com
Subject: Re: read(): varblk tape records...(& Fix for : read())
Date: Fri, 05 Mar 2004 00:43:24 +0000
Mime-Version: 1.0
Message-ID: <Sea2-F56obkiwnJFtnm0000ccdd@hotmail.com>
X-OriginalArrivalTime: 05 Mar 2004 00:43:25.0278 (UTC) FILETIME=[DE3FDFE0:01C4024A]

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

Hi Corinna,

As requested, the program which produces the run1/run2 output.

I also have a Native-NT version of the same program (which works 
as-expected, if you would like to see it too let me know.)

Jason.

_________________________________________________________________
SEEK: Now with over 50,000 dream jobs! Click here  
http://ninemsn.seek.com.au?hotmail

------=_NextPart_000_3954_3956_cd0
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

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;
    char buf2 [65535];

    printf ("read...");
    fflush (stdout);
    memset (buf2, ' ', 10);
    rc = read (fh, buf2, 65535);
    printf (" rc=%d\n", rc);
    buf2 [10] = 0;
    printf ("%s\n", buf2);
    disp_stat ();
    common ();
};

void my_write (int fh) {
    int rc;

    printf ("write...");
    fflush (stdout);
    rc = write (fh, buf, BLKLEN);
    printf (" rc=%d\n", rc);
    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 (0);

        disp_stat ();
        my_rew (fh);

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

        if (argc != 1) { // Use any parameter to test this case.

            set_blk (0);
            disp_stat ();
        };

        buf [0] = 'B';
        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_3954_3956_cd0
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_3954_3956_cd0--

- Raw text -


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