From csg@squall.waterspout.com  Sun Sep 10 16:21:18 2000
Return-Path: <csg@squall.waterspout.com>
Received: from squall.waterspout.com (squall.waterspout.com [208.13.60.154])
	by hub.freebsd.org (Postfix) with ESMTP id A8DBE37B423
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 10 Sep 2000 16:21:16 -0700 (PDT)
Received: (from csg@localhost)
	by squall.waterspout.com (8.9.3/8.9.3) id SAA42664;
	Sun, 10 Sep 2000 18:19:40 -0500 (EST)
	(envelope-from csg)
Message-Id: <200009102319.SAA42664@squall.waterspout.com>
Date: Sun, 10 Sep 2000 18:19:40 -0500 (EST)
From: csg@waterspout.com
Sender: csg@squall.waterspout.com
Reply-To: csg@waterspout.com
To: FreeBSD-gnats-submit@freebsd.org
Cc: ajk@waterspout.com, ab@eas.purdue.edu, dpm@vutar.com
Subject: voltag selector, and unload support for chio(1)
X-Send-Pr-Version: 3.2

>Number:         21178
>Category:       bin
>Synopsis:       voltag selector, and unload support for chio(1).
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ken
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 10 16:30:01 PDT 2000
>Closed-Date:    Sat Jan 18 01:10:49 CST 2003
>Last-Modified:  Sat Jan 18 01:10:49 CST 2003
>Originator:     C. Stephen Gunn
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
Waterpout Communications, Inc.
>Environment:

Most versions of FreeBSD.

>Description:

chio(1) provides no mechanism to select media by "voltag."
chio(1) provides no mechanism to return a media unit to its source.

>How-To-Repeat:

N/A - new feature request.

>Fix:

 o A pseudo-element type selector "voltag" that can be used to select
   source elements:

      chio move voltag VOLUME-03 drive 0

      chio exchange voltag VOLUME-03 voltag VOLUME-04

 o A new sub-command "unload" that returns a media unit to the source
   element reported by 'chio status -a':

      chio unload drive 0
      chio unload voltag VOLUME-03

A patch relative to 4.1-STABLE (should work on 5.0-CURRENT as well) is
available at:

    http://www.physics.purdue.edu/~csg/FreeBSD/chio.patch


>Release-Note:
>Audit-Trail:

From: Matthew Jacob <mjacob@feral.com>
To: csg@waterspout.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, ajk@waterspout.com,
	ab@eas.purdue.edu, dpm@vutar.com
Subject: Re: bin/21178: voltag selector, and unload support for chio(1)
Date: Sun, 10 Sep 2000 16:40:33 -0700 (PDT)

 Why doesn't somebody just merge the equivalent fixes from NetBSD's chio into
 FreeBSD? Or where they already done?
 
 
 > 
 > >Number:         21178
 > >Category:       bin
 > >Synopsis:       voltag selector, and unload support for chio(1).
 > >Confidential:   no
 > >Severity:       non-critical
 > >Priority:       low
 > >Responsible:    freebsd-bugs
 > >State:          open
 > >Quarter:        
 > >Keywords:       
 > >Date-Required:
 > >Class:          change-request
 > >Submitter-Id:   current-users
 > >Arrival-Date:   Sun Sep 10 16:30:01 PDT 2000
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     C. Stephen Gunn
 > >Release:        FreeBSD 4.0-STABLE i386
 > >Organization:
 > Waterpout Communications, Inc.
 > >Environment:
 > 
 > Most versions of FreeBSD.
 > 
 > >Description:
 > 
 > chio(1) provides no mechanism to select media by "voltag."
 > chio(1) provides no mechanism to return a media unit to its source.
 > 
 > >How-To-Repeat:
 > 
 > N/A - new feature request.
 > 
 > >Fix:
 > 
 >  o A pseudo-element type selector "voltag" that can be used to select
 >    source elements:
 > 
 >       chio move voltag VOLUME-03 drive 0
 > 
 >       chio exchange voltag VOLUME-03 voltag VOLUME-04
 > 
 >  o A new sub-command "unload" that returns a media unit to the source
 >    element reported by 'chio status -a':
 > 
 >       chio unload drive 0
 >       chio unload voltag VOLUME-03
 > 
 > A patch relative to 4.1-STABLE (should work on 5.0-CURRENT as well) is
 > available at:
 > 
 >     http://www.physics.purdue.edu/~csg/FreeBSD/chio.patch
 > 
 > 
 > >Release-Note:
 > >Audit-Trail:
 > >Unformatted:
 > 
 > 
 > To Unsubscribe: send mail to majordomo@FreeBSD.org
 > with "unsubscribe freebsd-bugs" in the body of the message
 > 
 
 

From: csg@waterspout.com (C. Stephen Gunn)
To: mjacob@feral.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/21178: voltag selector, and unload support for chio(1) 
Date: Sun, 10 Sep 2000 20:35:53 -0500

 On Sun, 10 Sep 2000 16:40:33 MST, Matthew Jacob wrote:
 
 > Why doesn't somebody just merge the equivalent fixes from NetBSD's chio in
 > to FreeBSD? Or where they already done?
 
 This isn't actually a fix.  It allows you to select a media unit
 to move by voltag.  It should make it easier for products like
 amanda to drive a tape-changer with barcode reader on FreeBSD.
 
 You can simply ask for a specific tape by voltag:
 
    chio move voltag VOLUME-03 drive 0
 
 The other feature is the "unload" command which checks the source
 parameter returned in the changer_element_status record.  If there's
 a source parameter, we "unload" the media by moving it back where
 the drive reports it came from.
 
 This the logic to request a certain tape (if you have a barcode
 reader or equivalent):
 
    chio unload drive <target-drive>
    chio move voltag <label> drive <target-drive>
 
 If the second one fails, the tape isn't in the changer, raccoons
 have eaten your barcodes, or the kids put bubblegum on the barcode
 reader optics. ;-)
 
  - Steve
 
 PS. the patch URL was incorrect before, I've fixed it (on my end).
 
 --
 C. Stephen Gunn                          URL: http://www.waterspout.com/
 WaterSpout Communications, Inc.        Email: csg@waterspout.com
 427 North 6th Street                   Phone: +1 765.742.6628
 Lafayette, IN  47901                     Fax: +1 765.742.0646
 

From: Matthew Jacob <mjacob@feral.com>
To: "C. Stephen Gunn" <csg@waterspout.com>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/21178: voltag selector, and unload support for chio(1) 
Date: Sun, 10 Sep 2000 20:55:15 -0700 (PDT)

 hmm. Sounds good, actually. I'm not chio's maintainer tho.
 
 
 
 

From: "Kenneth D. Merry" <ken@kdm.org>
To: csg@waterspout.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, ajk@waterspout.com,
	ab@eas.purdue.edu, dpm@vutar.com
Subject: Re: bin/21178: voltag selector, and unload support for chio(1)
Date: Mon, 11 Sep 2000 00:56:23 -0600

 On Sun, Sep 10, 2000 at 18:19:40 -0500, csg@waterspout.com wrote:
 > >Description:
 > 
 > chio(1) provides no mechanism to select media by "voltag."
 > chio(1) provides no mechanism to return a media unit to its source.
 > 
 > >How-To-Repeat:
 > 
 > N/A - new feature request.
 > 
 > >Fix:
 > 
 >  o A pseudo-element type selector "voltag" that can be used to select
 >    source elements:
 > 
 >       chio move voltag VOLUME-03 drive 0
 > 
 >       chio exchange voltag VOLUME-03 voltag VOLUME-04
 > 
 >  o A new sub-command "unload" that returns a media unit to the source
 >    element reported by 'chio status -a':
 > 
 >       chio unload drive 0
 >       chio unload voltag VOLUME-03
 > 
 > A patch relative to 4.1-STABLE (should work on 5.0-CURRENT as well) is
 > available at:
 > 
 >     http://www.physics.purdue.edu/~csg/FreeBSD/chio.patch
 
 Looks like a pretty good idea.
 
 I took a cursory glance through the patch, and noticed the 'XXX' comment
 about looking through pickers and portals.
 
 I'd suggest looking at them as well, even if it won't be used very often.
 (I've moved things from pickers and portals often enough, though.)
 
 I also wonder about the 'unload' keyword.  It almost sounds like something
 you might use to eject a tape or something.  What about calling it 'return'
 instead?  (I don't feel really strongly about this, but I figure we ought
 to make things intuitive, if possible.)
 
 Anyway, I'll try to give the patch a more thorough look-over in the next
 few days.  I won't be able to do more than that before committing it,
 though, since I don't have a test changer anymore.  (You've obviously
 tested it, though, so we should be okay in that department.)
 
 Ken
 -- 
 Kenneth Merry
 ken@kdm.org
 

From: csg@waterspout.com (C. Stephen Gunn)
To: "Kenneth D. Merry" <ken@kdm.org>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, ajk@waterspout.com,
	ab@eas.purdue.edu, dpm@vutar.com
Subject: Re: bin/21178: voltag selector, and unload support for chio(1) 
Date: Mon, 11 Sep 2000 08:50:13 -0500

 On Mon, 11 Sep 2000 00:56:23 CST, "Kenneth D. Merry" wrote:
 
 > Looks like a pretty good idea.
 > 
 > I took a cursory glance through the patch, and noticed the 'XXX' comment
 > about looking through pickers and portals.
 
 Yeah.  I didn't do that because of the way the ioctl() works to
 fetch information from the drive.  I guess it's not a big deal
 though.  Since I don't have any pickers or portals on my test drive,
 I'm not familiar with when a tape might be in one.  ( I guess I can
 figure the portal one out real easy ). 
 
 > I'd suggest looking at them as well, even if it won't be used very often.
 > (I've moved things from pickers and portals often enough, though.)
 
 I can add this.  I've got some other pending comments from my homeboys
 on the cc: line.  I'll address those as well, and submit a more recent
 patch early this week.
 
 > I also wonder about the 'unload' keyword.  It almost sounds like something
 > you might use to eject a tape or something. What about calling it 'return'
 > instead?  (I don't feel really strongly about this, but I figure we ought
 > to make things intuitive, if possible.)
 
 <grin> I use it exclusively to "unload" a tape from the drive to the 
 slot that it came from.  In my cursory investigation, drives (and
 perhaps pickers/portals) are the only changer elements with a valid
 source parameter.
 
 > Anyway, I'll try to give the patch a more thorough look-over in the next
 > few days.  I won't be able to do more than that before committing it,
 > though, since I don't have a test changer anymore.  (You've obviously
 > tested it, though, so we should be okay in that department.)
 
 Let me fixup some stuff based input, and I'll update the pr, and cc: you.
 
 Thanks!
 
  - Steve
 
 --
 C. Stephen Gunn                          URL: http://www.waterspout.com/
 WaterSpout Communications, Inc.        Email: csg@waterspout.com
 427 North 6th Street                   Phone: +1 765.742.6628
 Lafayette, IN  47901                     Fax: +1 765.742.0646
 

From: csg@waterspout.com (C. Stephen Gunn)
To: "Kenneth D. Merry" <ken@kdm.org>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, ajk@waterspout.com
Subject: Re: bin/21178: voltag selector, and unload support for chio(1) 
Date: Mon, 11 Sep 2000 23:21:45 -0500

 On Mon, 11 Sep 2000 00:56:23 CST, "Kenneth D. Merry" wrote:
 
 I've put a new patch online, same location:
 
    http://www.physics.purdue.edu/~csg/FreeBSD/chio.patch
 
 Some cleanups, command name changes, sanity check some pointers.
 
 > I'd suggest looking at them as well, even if it won't be used very often.
 > (I've moved things from pickers and portals often enough, though.)
 
 Done.
 
 > I also wonder about the 'unload' keyword.  It almost sounds like something
 > you might use to eject a tape or something.  What about calling it 'return'
 > instead?  (I don't feel really strongly about this, but I figure we ought
 > to make things intuitive, if possible.)
 
 I slept on this, and 'return' makes as much sense (if not more) than
 'unload' since it will work on any media unit that has a source attribute.
 
 > Anyway, I'll try to give the patch a more thorough look-over in the next
 > few days.  I won't be able to do more than that before committing it,
 > though, since I don't have a test changer anymore.  (You've obviously
 > tested it, though, so we should be okay in that department.)
 
 Seems to work for me (tm).
 
 Those who looked at it the first time are on the cc: line.  Have
 another look if you want. :)
 
  - Steve
 
 --
 C. Stephen Gunn                          URL: http://www.waterspout.com/
 WaterSpout Communications, Inc.        Email: csg@waterspout.com
 427 North 6th Street                   Phone: +1 765.742.6628
 Lafayette, IN  47901                     Fax: +1 765.742.0646
 
Responsible-Changed-From-To: freebsd-bugs->ken 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Sep 12 07:19:59 PDT 2000 
Responsible-Changed-Why:  
Ken asked for the new patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21178 

From: "Kenneth D. Merry" <ken@kdm.org>
To: "C. Stephen Gunn" <csg@waterspout.com>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, ajk@waterspout.com
Subject: Re: bin/21178: voltag selector, and unload support for chio(1)
Date: Fri, 15 Sep 2000 00:58:23 -0600

 --PEIAKu/WMn1b1Hv9
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 On Mon, Sep 11, 2000 at 23:21:45 -0500, C. Stephen Gunn wrote:
 > On Mon, 11 Sep 2000 00:56:23 CST, "Kenneth D. Merry" wrote:
 > 
 > I've put a new patch online, same location:
 > 
 >    http://www.physics.purdue.edu/~csg/FreeBSD/chio.patch
 > 
 > Some cleanups, command name changes, sanity check some pointers.
 
 Well, I took a look through it this evening, and I don't see any code
 problems.  It looks good!
 
 I've made some minor style changes, though, diffs against -current are
 attached.
 
 Ken
 -- 
 Kenneth Merry
 ken@kdm.org
 
 --PEIAKu/WMn1b1Hv9
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="chio.diffs.20000915"
 
 ==== //depot/FreeBSD-ken/src/bin/chio/chio.1#1 - /a/ken/perforce/FreeBSD-ken/src/bin/chio/chio.1 ====
 *** /tmp/tmp.83992.0	Fri Sep 15 00:55:41 2000
 --- /a/ken/perforce/FreeBSD-ken/src/bin/chio/chio.1	Thu Sep 14 21:04:10 2000
 ***************
 *** 69,88 ****
   .Pp
   A medium changer apparatus is made up of
   .Em elements .
 ! There are four element types:
   .Em picker
   (medium transport),
   .Em slot
   (storage),
   .Em portal
 ! (import/export), and
   .Em drive
 ! (data transfer).  In this command description, the shorthand
   .Em ET
   will be used to represent an element type, and
   .Em EU
 ! will be used to represent an element unit.  For example, to represent
 ! the first robotic arm in the changer, the
   .Em ET
   would be
   .Dq picker
 --- 69,95 ----
   .Pp
   A medium changer apparatus is made up of
   .Em elements .
 ! There are five element types:
   .Em picker
   (medium transport),
   .Em slot
   (storage),
   .Em portal
 ! (import/export),
   .Em drive
 ! (data transfer), and
 ! .Em voltag
 ! (select by volume identifier).  The
 ! .Em voltag
 ! pseudo-element type allows the selection of tapes by their volume tag
 ! (typically a barcode on the tape).
 ! .Pp
 ! In this command description, the shorthand
   .Em ET
   will be used to represent an element type, and
   .Em EU
 ! will be used to represent an element unit.
 ! For example, to represent the first robotic arm in the changer, the
   .Em ET
   would be
   .Dq picker
 ***************
 *** 137,142 ****
 --- 144,158 ----
   .Ic exchange
   operation; the changer must have multiple free pickers or emulate
   multiple free pickers with transient storage.
 + .It Xo Nm return
 + .Ar <from ET> <from EU>
 + .Xc
 + Return the media unit to its source element.
 + This command will query the status of the specified media unit, and
 + will move it to the element specified in its source attribute.
 + This is a convenient way to return media from a drive or portal
 + to its previous element in the changer.
 + .Pp
   .It Xo Nm position
   .Ar <to ET> <to EU>
   .Op Ar inv
 ***************
 *** 246,251 ****
 --- 262,272 ----
   .Bl -tag -width indent
   .It Nm chio move slot 3 drive 0
   Move the media in slot 3 (fourth slot) to drive 0 (first drive).
 + .It Nm chio move voltag VOLUME01 drive 0
 + Move the media with the barcode VOLUME01 to drive 0 (first drive).
 + .It Nm chio return drive 0
 + Remove the tape from drive 0 (first drive) and return it to its original
 + location in the rack.
   .It Nm chio setpicker 2
   Configure the changer to use picker 2 (third picker) for operations.
   .El
 ***************
 *** 265,268 ****
   for And Communications, http://www.and.com/.
   .br
   Additional work by
 ! .An Hans Huebner Aq hans@artcom.de
 --- 286,292 ----
   for And Communications, http://www.and.com/.
   .br
   Additional work by
 ! .An Hans Huebner
 ! .Aq hans@artcom.de
 ! and Steve Gunn
 ! .Aq csg@waterspout.com
 ==== //depot/FreeBSD-ken/src/bin/chio/chio.c#1 - /a/ken/perforce/FreeBSD-ken/src/bin/chio/chio.c ====
 *** /tmp/tmp.83992.1	Fri Sep 15 00:55:41 2000
 --- /a/ken/perforce/FreeBSD-ken/src/bin/chio/chio.c	Fri Sep 15 00:49:25 2000
 ***************
 *** 32,37 ****
 --- 32,38 ----
    */
   /*
    * Additional Copyright (c) 1997, by Matthew Jacob, for NASA/Ames Research Ctr.
 +  * Addidional Copyright (c) 2000, by C. Stephen Gunn, Waterspout Communications
    */
   
   #ifndef lint
 ***************
 *** 65,70 ****
 --- 66,74 ----
   static	int is_special __P((char *));
   static	const char *bits_to_string __P((int, const char *));
   
 + static	void find_element __P((char *, u_int16_t *, u_int16_t *));
 + static	struct changer_element_status *get_element_status __P((u_int16_t, u_int16_t));
 + 
   static	int do_move __P((char *, int, char **));
   static	int do_exchange __P((char *, int, char **));
   static	int do_position __P((char *, int, char **));
 ***************
 *** 73,86 ****
 --- 77,96 ----
   static	int do_setpicker __P((char *, int, char **));
   static	int do_status __P((char *, int, char **));
   static	int do_ielem __P((char *, int, char **));
 + static	int do_return __P((char *, int, char **));
   static	int do_voltag __P((char *, int, char **));
   
 + #ifndef CHET_VT
 + #define	CHET_VT		10			/* Completely Arbitrary */
 + #endif
 + 
   /* Valid changer element types. */
   const struct element_type elements[] = {
   	{ "drive",		CHET_DT },
   	{ "picker",		CHET_MT },
   	{ "portal",		CHET_IE },
   	{ "slot",		CHET_ST },
 + 	{ "voltag",		CHET_VT },	/* Select tapes by barcode */
   	{ NULL,			0 },
   };
   
 ***************
 *** 94,99 ****
 --- 104,110 ----
   	{ "position",		do_position },
   	{ "setpicker",		do_setpicker },
   	{ "status",		do_status },
 + 	{ "return",		do_return },
   	{ "voltag",		do_voltag },
   	{ NULL,			0 },
   };
 ***************
 *** 196,209 ****
   	cmd.cm_fromtype = parse_element_type(*argv);
   	++argv; --argc;
   
 ! 	/* <from EU> */
 ! 	cmd.cm_fromunit = parse_element_unit(*argv);
   	++argv; --argc;
   
   	/* <to ET> */
   	cmd.cm_totype = parse_element_type(*argv);
   	++argv; --argc;
   
   	/* <to EU> */
   	cmd.cm_tounit = parse_element_unit(*argv);
   	++argv; --argc;
 --- 207,230 ----
   	cmd.cm_fromtype = parse_element_type(*argv);
   	++argv; --argc;
   
 ! 	/* Check for voltag virtual type */
 ! 	if (CHET_VT == cmd.cm_fromtype) {
 ! 		find_element(*argv, &cmd.cm_fromtype, &cmd.cm_fromunit);
 ! 	} else {
 ! 		/* <from EU> */
 ! 		cmd.cm_fromunit = parse_element_unit(*argv);
 ! 	}
   	++argv; --argc;
   
   	/* <to ET> */
   	cmd.cm_totype = parse_element_type(*argv);
   	++argv; --argc;
   
 + 	/* Check for voltag virtual type, and report error */
 + 	if (CHET_VT == cmd.cm_totype)
 + 		errx(1,"%s: voltag only makes sense as an element source",
 + 		     cname);
 + 
   	/* <to EU> */
   	cmd.cm_tounit = parse_element_unit(*argv);
   	++argv; --argc;
 ***************
 *** 267,282 ****
   	cmd.ce_srctype = parse_element_type(*argv);
   	++argv; --argc;
   
 ! 	/* <src EU> */
 ! 	cmd.ce_srcunit = parse_element_unit(*argv);
   	++argv; --argc;
   
   	/* <dst1 ET> */
   	cmd.ce_fdsttype = parse_element_type(*argv);
   	++argv; --argc;
   
 ! 	/* <dst1 EU> */
 ! 	cmd.ce_fdstunit = parse_element_unit(*argv);
   	++argv; --argc;
   
   	/*
 --- 288,313 ----
   	cmd.ce_srctype = parse_element_type(*argv);
   	++argv; --argc;
   
 ! 	/* Check for voltag virtual type */
 ! 	if (CHET_VT == cmd.ce_srctype) {
 ! 		find_element(*argv, &cmd.ce_srctype, &cmd.ce_srcunit);
 ! 	} else {
 ! 		/* <from EU> */
 ! 		cmd.ce_srcunit = parse_element_unit(*argv);
 ! 	}
   	++argv; --argc;
   
   	/* <dst1 ET> */
   	cmd.ce_fdsttype = parse_element_type(*argv);
   	++argv; --argc;
   
 ! 	/* Check for voltag virtual type */
 ! 	if (CHET_VT == cmd.ce_fdsttype) {
 ! 		find_element(*argv, &cmd.ce_fdsttype, &cmd.ce_fdstunit);
 ! 	} else {
 ! 		/* <from EU> */
 ! 		cmd.ce_fdstunit = parse_element_unit(*argv);
 ! 	}
   	++argv; --argc;
   
   	/*
 ***************
 *** 294,299 ****
 --- 325,334 ----
   	cmd.ce_sdsttype = parse_element_type(*argv);
   	++argv; --argc;
   
 + 	if (CHET_VT == cmd.ce_sdsttype)
 + 		errx(1,"%s %s: voltag only makes sense as an element source",
 + 		     cname, *argv);
 + 
   	/* <dst2 EU> */
   	cmd.ce_sdstunit = parse_element_unit(*argv);
   	++argv; --argc;
 ***************
 *** 653,661 ****
   		cesr.cesr_element_base = base;
   		cesr.cesr_element_count = count;
   		/* Allocate storage for the status structures. */
 ! 		cesr.cesr_element_status
 ! 		  = (struct changer_element_status *) 
 ! 		  malloc(count * sizeof(struct changer_element_status));
   		
   		if (!cesr.cesr_element_status)
   			errx(1, "can't allocate status storage");
 --- 688,696 ----
   		cesr.cesr_element_base = base;
   		cesr.cesr_element_count = count;
   		/* Allocate storage for the status structures. */
 ! 		cesr.cesr_element_status =
 ! 		  (struct changer_element_status *) 
 ! 		  calloc(count, sizeof(struct changer_element_status));
   		
   		if (!cesr.cesr_element_status)
   			errx(1, "can't allocate status storage");
 ***************
 *** 934,939 ****
 --- 969,1204 ----
   		*bp = '>';
   
   	return (buf);
 + }
 + /*
 +  * do_return()
 +  * 
 +  * Given an element reference, ask the changer/picker to move that
 +  * element back to its source slot.
 +  */
 + static int
 + do_return(cname, argc, argv)
 + 	char *cname;
 + 	int  argc;
 + 	char **argv;
 + {
 + 	struct changer_element_status *ces;
 + 	struct changer_move cmd;
 + 	u_int16_t	type, element;
 + 
 + 	++argv; --argc;
 + 
 + 	if (argc < 2) {
 + 		warnx("%s: too few arguments", cname);
 + 		goto usage;
 + 	} else if (argc > 3) {
 + 		warnx("%s: too many arguments", cname);
 + 		goto usage;
 + 	}
 + 
 + 	type = parse_element_type(*argv);
 + 	++argv; --argc;
 + 	
 + 	/* Handle voltag virtual Changer Element Type */
 + 	if (CHET_VT == type) {
 + 		find_element(*argv, &type, &element);
 + 	} else {
 + 		element = parse_element_unit(*argv);
 + 	}
 + 	++argv; --argc;
 + 
 + 	ces = get_element_status(type, element);	/* Get the status */
 + 
 + 	if (NULL == ces)
 + 		errx(1, "%s: null element status pointer", cname);
 + 
 + 	if (!(ces->ces_flags & CES_SOURCE_VALID))
 + 		errx(1, "%s: no source information", cname);
 + 
 + 	(void) memset(&cmd, 0, sizeof(cmd));
 + 
 + 	cmd.cm_fromtype = type;
 + 	cmd.cm_fromunit = element;
 + 	cmd.cm_totype = ces->ces_source_type;
 + 	cmd.cm_tounit = ces->ces_source_addr;
 + 
 + 	if (ioctl(changer_fd, CHIOMOVE, &cmd) == -1)
 + 		err(1, "%s: CHIOMOVE", changer_name);
 + 	free(ces);
 + 
 + 	return(0);
 + 
 + usage:
 + 	(void) fprintf(stderr, "usage: %s %s "
 + 	    "<from ET> <from EU>\n", __progname, cname);
 + 	return(1);
 + }
 + 
 + /*
 +  * get_element_status()
 +  *
 +  * return a *cesr for the specified changer element.  This
 +  * routing will malloc()/calloc() the memory.  The caller
 +  * should free() it when done.
 +  */
 + static struct changer_element_status *
 + get_element_status(type, element)
 + 	u_int16_t	type;
 + 	u_int16_t	element;
 + {
 + 	struct changer_element_status_request cesr;
 + 	struct changer_element_status *ces;
 + 	
 + 	ces = (struct changer_element_status *)
 + 	    calloc(1, sizeof(struct changer_element_status));
 + 
 + 	if (NULL == ces)
 + 		errx(1, "can't allocate status storage");
 + 
 + 	(void)memset(&cesr, 0, sizeof(cesr));
 + 
 + 	cesr.cesr_element_type = type;
 + 	cesr.cesr_element_base = element;
 + 	cesr.cesr_element_count = 1;		/* Only this one element */
 + 	cesr.cesr_flags |= CESR_VOLTAGS;	/* Grab voltags as well */
 + 	cesr.cesr_element_status = ces;
 + 
 + 	if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
 + 		free(ces);
 + 		err(1, "%s: CHIOGSTATUS", changer_name);
 + 		/* NOTREACHED */
 + 	}
 + 
 + 	return ces;
 + }
 + 
 + 
 + /*
 +  * find_element()
 +  * 
 +  * Given a <voltag> find the chager element and unit, or exit
 +  * with an error if it isn't found.  We grab the changer status
 +  * and iterate until we find a match, or crap out.
 +  */
 + static void
 + find_element(voltag, et, eu)
 + 	char *voltag;
 + 	u_int16_t *et;
 + 	u_int16_t *eu;
 + {
 + 	struct changer_params cp;
 + 	struct changer_element_status_request cesr;
 + 	struct changer_element_status *ch_ces, *ces;
 + 	int elem, total_elem, found = 0;
 + 
 + 	/*
 + 	 * Get the changer parameters, we're interested in the counts
 + 	 * for all types of elements to perform our search.
 + 	 */
 + 	if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
 + 		err(1, "%s: CHIOGPARAMS", changer_name);
 + 
 + 	/* Allocate some memory for the results */
 + 	total_elem = (cp.cp_nslots + cp.cp_ndrives
 + 	    + cp.cp_npickers + cp.cp_nportals);
 + 	
 + 	ch_ces = (struct changer_element_status *)
 + 	    calloc(total_elem, sizeof(struct changer_element_status));
 + 
 + 	if (NULL == ch_ces)
 + 		errx(1, "can't allocate status storage");
 + 
 + 	ces = ch_ces;
 + 
 + 	/* Read in the changer slots */
 + 	if (cp.cp_nslots > 0) {
 + 		cesr.cesr_element_type = CHET_ST;
 + 		cesr.cesr_element_base = 0;
 + 		cesr.cesr_element_count = cp.cp_nslots;
 + 		cesr.cesr_flags |= CESR_VOLTAGS;
 + 		cesr.cesr_element_status = ces;
 + 
 + 		if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
 + 			free(ch_ces);
 + 			err(1, "%s: CHIOGSTATUS", changer_name);
 + 		}
 + 		ces += cp.cp_nslots;
 + 	}	
 + 
 + 	/* Read in the drive information */
 + 	if (cp.cp_ndrives > 0 ) {
 + 
 + 		(void) memset(&cesr, 0, sizeof(cesr));
 + 		cesr.cesr_element_type = CHET_DT;
 + 		cesr.cesr_element_base = 0;
 + 		cesr.cesr_element_count = cp.cp_ndrives;
 + 		cesr.cesr_flags |= CESR_VOLTAGS;
 + 		cesr.cesr_element_status = ces;
 + 
 + 		if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
 + 			free(ch_ces);
 + 			err(1, "%s: CHIOGSTATUS", changer_name);
 + 		}
 + 		ces += cp.cp_ndrives;
 + 	}
 + 
 + 	/* Read in the portal information */
 + 	if (cp.cp_nportals > 0 ) {
 + 		(void) memset(&cesr, 0, sizeof(cesr));
 + 		cesr.cesr_element_type = CHET_IE;
 + 		cesr.cesr_element_base = 0;
 + 		cesr.cesr_element_count = cp.cp_nportals;
 + 		cesr.cesr_flags |= CESR_VOLTAGS;
 + 		cesr.cesr_element_status = ces;
 + 
 + 		if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
 + 			free(ch_ces);
 + 			err(1, "%s: CHIOGSTATUS", changer_name);
 + 		}
 + 		ces += cp.cp_nportals;
 + 	}
 + 
 + 	/* Read in the picker information */
 + 	if (cp.cp_npickers > 0) {
 + 		(void) memset(&cesr, 0, sizeof(cesr));
 + 		cesr.cesr_element_type = CHET_MT;
 + 		cesr.cesr_element_base = 0;
 + 		cesr.cesr_element_count = cp.cp_npickers;
 + 		cesr.cesr_flags |= CESR_VOLTAGS;
 + 		cesr.cesr_element_status = ces;
 + 
 + 		if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
 + 			free(ch_ces);
 + 			err(1, "%s: CHIOGSTATUS", changer_name);
 + 		}
 + 	}
 + 
 + 	/*
 + 	 * Now search the list the specified <voltag>
 + 	 */	
 + 	for (elem = 0; elem <= total_elem; ++elem) {
 + 
 + 		ces = &ch_ces[elem];
 + 
 + 		/* Make sure we have a tape in this element */
 + 		if ((ces->ces_flags & (CES_STATUS_ACCESS|CES_STATUS_FULL))
 + 		    != (CES_STATUS_ACCESS|CES_STATUS_FULL))
 + 			continue;
 + 
 + 		/* Check to see if it is our target */
 + 		if (strcasecmp(voltag, ces->ces_pvoltag.cv_volid) == 0) {
 + 			*et = ces->ces_type;
 + 			*eu = ces->ces_addr;
 + 			++found;
 + 			break;
 + 		}
 + 	}
 + 	if (!found) {
 + 		errx(1, "%s: unable to locate voltag: %s", changer_name,
 + 		     voltag);
 + 	}
 + 	free(ch_ces);
 + 	return;
   }
   
   static void
 
 --PEIAKu/WMn1b1Hv9--
 
State-Changed-From-To: open->suspended 
State-Changed-By: ken 
State-Changed-When: Sun Sep 17 23:09:18 PDT 2000 
State-Changed-Why:  
I have committed the latest version of these patches to -current.  Once 
they've had a chance to sit in -current for a little while, I'll merge them 
to RELENG_4.  Thanks Steve! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21178 
State-Changed-From-To: suspended->closed 
State-Changed-By: petef 
State-Changed-When: Sat Jan 18 01:10:49 CST 2003 
State-Changed-Why:  
This support is in RELENG_4. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21178 
>Unformatted:
