Skip to content

Commit

Permalink
Reverting changes that have not yet been agreed
Browse files Browse the repository at this point in the history
Open questions: named vs unnamed structures
                what field go in device specfic structures vs general structure
                use of malloc vs static
                naming convention
  • Loading branch information
janjaeger committed Aug 18, 2011
1 parent a2f8ebf commit bf34bf7
Show file tree
Hide file tree
Showing 37 changed files with 3,208 additions and 3,462 deletions.
2 changes: 0 additions & 2 deletions CHANGES
@@ -1,5 +1,3 @@
17 Aug 2011 Change dev->filename to pointer - P. Gorlinsky
17 Aug 2011 Move device unique data fields into devunique union. - P.Gorlinsky
12 Aug 2011 Fix color message and timestamp problem. Removed LOGMSG macro.
change log_msg to logmsg. - P. Gorlinsky
12 Aug 2011 Add logmsg() support for utilities. - P. Gorlinsky
Expand Down
126 changes: 57 additions & 69 deletions awstape.c
Expand Up @@ -42,17 +42,10 @@ void close_awstape (DEVBLK *dev)
WRMSG (HHC00201, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "aws");
close(dev->fd);
}
if ( dev->filename != NULL )
{
free(dev->filename);
dev->filename = NULL;
}

dev->filename = strdup( TAPE_UNLOADED );

strlcpy(dev->filename, TAPE_UNLOADED, sizeof(dev->filename));
dev->fd=-1;
dev->devunique.tape_dev.blockid = 0;
dev->devunique.tape_dev.fenced = 0;
dev->blockid = 0;
dev->fenced = 0;
return;
}

Expand All @@ -69,11 +62,11 @@ int rewind_awstape (DEVBLK *dev,BYTE *unitstat,BYTE code)
build_senseX(TAPE_BSENSE_REWINDFAILED,dev,unitstat,code);
return -1;
}
dev->devunique.tape_dev.nxtblkpos=0;
dev->devunique.tape_dev.prvblkpos=-1;
dev->devunique.tape_dev.curfilen=1;
dev->devunique.tape_dev.blockid=0;
dev->devunique.tape_dev.fenced = 0;
dev->nxtblkpos=0;
dev->prvblkpos=-1;
dev->curfilen=1;
dev->blockid=0;
dev->fenced = 0;
return 0;
}

Expand All @@ -83,22 +76,22 @@ int rewind_awstape (DEVBLK *dev,BYTE *unitstat,BYTE code)
/*-------------------------------------------------------------------*/
int passedeot_awstape (DEVBLK *dev)
{
if( dev->devunique.tape_dev.nxtblkpos == 0 )
if( dev->nxtblkpos == 0 )
{
dev->devunique.tape_dev.eotwarning = 0;
dev->eotwarning = 0;
return 0;
}
if( dev->devunique.tape_dev.tdparms.maxsize == 0 )
if( dev->tdparms.maxsize == 0 )
{
dev->devunique.tape_dev.eotwarning = 0;
dev->eotwarning = 0;
return 0;
}
if( dev->devunique.tape_dev.nxtblkpos + dev->devunique.tape_dev.eotmargin > dev->devunique.tape_dev.tdparms.maxsize )
if( dev->nxtblkpos + dev->eotmargin > dev->tdparms.maxsize )
{
dev->devunique.tape_dev.eotwarning = 1;
dev->eotwarning = 1;
return 1;
}
dev->devunique.tape_dev.eotwarning = 0;
dev->eotwarning = 0;
return 0;
}

Expand Down Expand Up @@ -126,7 +119,7 @@ char pathname[MAX_PATH]; /* file path in host format */

/* Open the AWSTAPE file */
hostpath(pathname, dev->filename, sizeof(pathname));
if(!dev->devunique.tape_dev.tdparms.logical_readonly)
if(!dev->tdparms.logical_readonly)
{
rc = HOPEN (pathname, O_RDWR | O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP );
if ( rc < 0 && !sysblk.noautoinit )
Expand Down Expand Up @@ -154,9 +147,9 @@ char pathname[MAX_PATH]; /* file path in host format */
}

/* If file is read-only, attempt to open again */
if (dev->devunique.tape_dev.tdparms.logical_readonly || (rc < 0 && (EROFS == errno || EACCES == errno)))
if (dev->tdparms.logical_readonly || (rc < 0 && (EROFS == errno || EACCES == errno)))
{
dev->devunique.tape_dev.readonly = 1;
dev->readonly = 1;
rc = HOPEN (pathname, O_RDONLY | O_BINARY, S_IRUSR | S_IRGRP );
}

Expand All @@ -165,12 +158,7 @@ char pathname[MAX_PATH]; /* file path in host format */
{
WRMSG (HHC00205, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "aws", "open()", strerror(errno));

if (dev->filename != NULL)
{
free(dev->filename);
dev->filename = NULL;
}
dev->filename = strdup( TAPE_UNLOADED );
strlcpy( dev->filename, TAPE_UNLOADED, sizeof(dev->filename) );
build_senseX(TAPE_BSENSE_TAPELOADFAIL,dev,unitstat,code);
return -1;
}
Expand Down Expand Up @@ -264,7 +252,7 @@ int blklen = 0; /* Total length of block */
U16 seglen; /* Data length of segment */

/* Initialize current block position */
blkpos = dev->devunique.tape_dev.nxtblkpos;
blkpos = dev->nxtblkpos;

/* Read block segments until end of block */
do
Expand Down Expand Up @@ -335,16 +323,16 @@ U16 seglen; /* Data length of segment */
} while ((awshdr.flags1 & AWSTAPE_FLAG1_ENDREC) == 0);

/* Calculate the offsets of the next and previous blocks */
dev->devunique.tape_dev.prvblkpos = dev->devunique.tape_dev.nxtblkpos;
dev->devunique.tape_dev.nxtblkpos = blkpos;
dev->prvblkpos = dev->nxtblkpos;
dev->nxtblkpos = blkpos;

/* Increment the block number */
dev->devunique.tape_dev.blockid++;
dev->blockid++;

/* Increment file number and return zero if tapemark was read */
if (blklen == 0)
{
dev->devunique.tape_dev.curfilen++;
dev->curfilen++;
return 0; /* UX will be set by caller */
}

Expand All @@ -369,22 +357,22 @@ off_t blkpos; /* Offset of block header */
U16 prvblkl; /* Length of previous block */

/* Initialize current block position and previous block length */
blkpos = dev->devunique.tape_dev.nxtblkpos;
blkpos = dev->nxtblkpos;
prvblkl = 0;

/* Determine previous block length if not at start of tape */
if (dev->devunique.tape_dev.nxtblkpos > 0)
if (dev->nxtblkpos > 0)
{
/* Reread the previous block header */
rc = readhdr_awstape (dev, dev->devunique.tape_dev.prvblkpos, &awshdr, unitstat,code);
rc = readhdr_awstape (dev, dev->prvblkpos, &awshdr, unitstat,code);
if (rc < 0) return -1;

/* Extract the block length from the block header */
prvblkl = ((U16)(awshdr.curblkl[1]) << 8)
| awshdr.curblkl[0];

/* Recalculate the offset of the next block */
blkpos = dev->devunique.tape_dev.prvblkpos + sizeof(awshdr) + prvblkl;
blkpos = dev->prvblkpos + sizeof(awshdr) + prvblkl;
}

/* Reposition file to the new block header */
Expand All @@ -399,9 +387,9 @@ U16 prvblkl; /* Length of previous block */
return -1;
}
/* ISW: Determine if we are passed maxsize */
if(dev->devunique.tape_dev.tdparms.maxsize>0)
if(dev->tdparms.maxsize>0)
{
if((off_t)(dev->devunique.tape_dev.nxtblkpos+blklen+sizeof(awshdr)) > dev->devunique.tape_dev.tdparms.maxsize)
if((off_t)(dev->nxtblkpos+blklen+sizeof(awshdr)) > dev->tdparms.maxsize)
{
build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
return -1;
Expand Down Expand Up @@ -435,8 +423,8 @@ U16 prvblkl; /* Length of previous block */
}

/* Calculate the offsets of the next and previous blocks */
dev->devunique.tape_dev.nxtblkpos = blkpos + sizeof(awshdr) + blklen;
dev->devunique.tape_dev.prvblkpos = blkpos;
dev->nxtblkpos = blkpos + sizeof(awshdr) + blklen;
dev->prvblkpos = blkpos;

/* Write the data block */
rc = write (dev->fd, buf, blklen);
Expand All @@ -455,10 +443,10 @@ U16 prvblkl; /* Length of previous block */
return -1;
}

dev->devunique.tape_dev.blockid++;
dev->blockid++;

/* Set new physical EOF */
do rc = ftruncate( dev->fd, dev->devunique.tape_dev.nxtblkpos );
do rc = ftruncate( dev->fd, dev->nxtblkpos );
while (EINTR == rc);

if (rc != 0)
Expand Down Expand Up @@ -491,22 +479,22 @@ off_t blkpos; /* Offset of block header */
U16 prvblkl; /* Length of previous block */

/* Initialize current block position and previous block length */
blkpos = dev->devunique.tape_dev.nxtblkpos;
blkpos = dev->nxtblkpos;
prvblkl = 0;

/* Determine previous block length if not at start of tape */
if (dev->devunique.tape_dev.nxtblkpos > 0)
if (dev->nxtblkpos > 0)
{
/* Reread the previous block header */
rc = readhdr_awstape (dev, dev->devunique.tape_dev.prvblkpos, &awshdr, unitstat,code);
rc = readhdr_awstape (dev, dev->prvblkpos, &awshdr, unitstat,code);
if (rc < 0) return -1;

/* Extract the block length from the block header */
prvblkl = ((U16)(awshdr.curblkl[1]) << 8)
| awshdr.curblkl[0];

/* Recalculate the offset of the next block */
blkpos = dev->devunique.tape_dev.prvblkpos + sizeof(awshdr) + prvblkl;
blkpos = dev->prvblkpos + sizeof(awshdr) + prvblkl;
}

/* Reposition file to the new block header */
Expand All @@ -520,9 +508,9 @@ U16 prvblkl; /* Length of previous block */
return -1;
}
/* ISW: Determine if we are passed maxsize */
if(dev->devunique.tape_dev.tdparms.maxsize>0)
if(dev->tdparms.maxsize>0)
{
if((off_t)(dev->devunique.tape_dev.nxtblkpos+sizeof(awshdr)) > dev->devunique.tape_dev.tdparms.maxsize)
if((off_t)(dev->nxtblkpos+sizeof(awshdr)) > dev->tdparms.maxsize)
{
build_senseX(TAPE_BSENSE_ENDOFTAPE,dev,unitstat,code);
return -1;
Expand All @@ -549,14 +537,14 @@ U16 prvblkl; /* Length of previous block */
return -1;
}

dev->devunique.tape_dev.blockid++;
dev->blockid++;

/* Calculate the offsets of the next and previous blocks */
dev->devunique.tape_dev.nxtblkpos = blkpos + sizeof(awshdr);
dev->devunique.tape_dev.prvblkpos = blkpos;
dev->nxtblkpos = blkpos + sizeof(awshdr);
dev->prvblkpos = blkpos;

/* Set new physical EOF */
do rc = ftruncate( dev->fd, dev->devunique.tape_dev.nxtblkpos );
do rc = ftruncate( dev->fd, dev->nxtblkpos );
while (EINTR == rc);

if (rc != 0)
Expand All @@ -583,7 +571,7 @@ U16 prvblkl; /* Length of previous block */
int sync_awstape (DEVBLK *dev, BYTE *unitstat,BYTE code)
{
/* Unit check if tape is write-protected */
if (dev->devunique.tape_dev.readonly)
if (dev->readonly)
{
build_senseX(TAPE_BSENSE_WRITEPROTECT,dev,unitstat,code);
return -1;
Expand Down Expand Up @@ -621,7 +609,7 @@ int blklen = 0; /* Total length of block */
U16 seglen; /* Data length of segment */

/* Initialize current block position */
blkpos = dev->devunique.tape_dev.nxtblkpos;
blkpos = dev->nxtblkpos;

/* Read block segments until end of block */
do
Expand All @@ -647,14 +635,14 @@ U16 seglen; /* Data length of segment */
} while ((awshdr.flags1 & AWSTAPE_FLAG1_ENDREC) == 0);

/* Calculate the offsets of the next and previous blocks */
dev->devunique.tape_dev.prvblkpos = dev->devunique.tape_dev.nxtblkpos;
dev->devunique.tape_dev.nxtblkpos = blkpos;
dev->prvblkpos = dev->nxtblkpos;
dev->nxtblkpos = blkpos;

/* Increment current file number if tapemark was skipped */
if (blklen == 0)
dev->devunique.tape_dev.curfilen++;
dev->curfilen++;

dev->devunique.tape_dev.blockid++;
dev->blockid++;

/* Return block length or zero if tapemark */
return blklen;
Expand All @@ -678,14 +666,14 @@ U16 prvblkl; /* Length of previous block */
off_t blkpos; /* Offset of block header */

/* Unit check if already at start of tape */
if (dev->devunique.tape_dev.nxtblkpos == 0)
if (dev->nxtblkpos == 0)
{
build_senseX(TAPE_BSENSE_LOADPTERR,dev,unitstat,code);
return -1;
}

/* Backspace to previous block position */
blkpos = dev->devunique.tape_dev.prvblkpos;
blkpos = dev->prvblkpos;

/* Read the 6-byte block header */
rc = readhdr_awstape (dev, blkpos, &awshdr, unitstat,code);
Expand All @@ -698,14 +686,14 @@ off_t blkpos; /* Offset of block header */
| awshdr.prvblkl[0];

/* Calculate the offset of the previous block */
dev->devunique.tape_dev.prvblkpos = blkpos - sizeof(awshdr) - prvblkl;
dev->devunique.tape_dev.nxtblkpos = blkpos;
dev->prvblkpos = blkpos - sizeof(awshdr) - prvblkl;
dev->nxtblkpos = blkpos;

/* Decrement current file number if backspaced over tapemark */
if (curblkl == 0)
dev->devunique.tape_dev.curfilen--;
dev->curfilen--;

dev->devunique.tape_dev.blockid--;
dev->blockid--;

/* Return block length or zero if tapemark */
return curblkl;
Expand Down Expand Up @@ -760,7 +748,7 @@ int rc; /* Return code */
while (1)
{
/* Exit if now at start of tape */
if (dev->devunique.tape_dev.nxtblkpos == 0)
if (dev->nxtblkpos == 0)
{
build_senseX(TAPE_BSENSE_LOADPTERR,dev,unitstat,code);
return -1;
Expand Down

0 comments on commit bf34bf7

Please sign in to comment.