Date: Tue, 10 Feb 1998 21:05:28 -0800 (PST) From: jason_smethers@bigfoot.com To: freebsd-gnats-submit@FreeBSD.ORG Subject: bin/5712: /bin/chio code cleaup and option added Message-ID: <199802110505.VAA19832@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 5712 >Category: bin >Synopsis: /bin/chio code cleaup and option added >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: Tue Feb 10 21:10:10 PST 1998 >Last-Modified: >Originator: Jason Smethers >Organization: >Release: 3.0-Current >Environment: FreeBSD p90unix.vipersystems.com 3.0-CURRENT FreeBSD 3.0-CURRENT #1: Sun Feb 8 17:26:35 CST 1998 root@p90unix.vipersystems.com:/usr/src/sys/compile/P90UNIX i386 >Description: Gerneral code cleanup and IELEM option added for which system header file chio.h was modified. Updated man page. >How-To-Repeat: >Fix: diff -c -r /usr/src/bin/chio/chio.1 /usr/local/src/bin/chio/chio.1 *** /usr/src/bin/chio/chio.1 Sat Sep 13 11:01:18 1997 --- /usr/local/src/bin/chio/chio.1 Sun Feb 8 21:16:55 1998 *************** *** 12,18 **** .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software ! .\" must display the following acknowledgements: .\" This product includes software developed by Jason R. Thorpe .\" for And Communications, http://www.and.com/ .\" 4. The name of the author may not be used to endorse or promote products --- 12,18 ---- .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software ! .\" must display the following acknowledgments: .\" This product includes software developed by Jason R. Thorpe .\" for And Communications, http://www.and.com/ .\" 4. The name of the author may not be used to endorse or promote products *************** *** 177,183 **** .It Nm ACCESS Media in this element is accessible by a picker. .It Nm EXENAB ! Element supports passing media (exporting) to an outsite human operator. .It Nm INENAB Element supports receiving media (importing) from an outside human operator. .El --- 177,185 ---- .It Nm ACCESS Media in this element is accessible by a picker. .It Nm EXENAB ! Element supports passing media (exporting) to an outside human operator. ! .It Nm IELEM ! Perform an \fBINITIALIZE ELEMENT STATUS\fR operation on the changer. .It Nm INENAB Element supports receiving media (importing) from an outside human operator. .El *************** *** 188,200 **** Moves the media in slot 3 (fourth slot) to drive 0 (first drive). .Pp .Nm chio setpicker 2 Configures the changer to use picker 2 (third picker) for operations. .Pp .Sh FILES /dev/ch0 - default changer device .Sh SEE ALSO .Xr mt 1 , ! .Xr ch 4 , .Xr mount 8 . .Sh AUTHOR The --- 190,203 ---- Moves the media in slot 3 (fourth slot) to drive 0 (first drive). .Pp .Nm chio setpicker 2 + .Pp Configures the changer to use picker 2 (third picker) for operations. .Pp .Sh FILES /dev/ch0 - default changer device .Sh SEE ALSO .Xr mt 1 , ! .Xr ch 4 .Xr mount 8 . .Sh AUTHOR The diff -c -r /usr/src/bin/chio/chio.c /usr/local/src/bin/chio/chio.c *** /usr/src/bin/chio/chio.c Fri Jun 6 01:32:09 1997 --- /usr/local/src/bin/chio/chio.c Sun Feb 8 19:08:22 1998 *************** *** 13,19 **** * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software ! * must display the following acknowledgements: * This product includes software developed by Jason R. Thorpe * for And Communications, http://www.and.com/ * 4. The name of the author may not be used to endorse or promote products --- 13,19 ---- * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software ! * must display the following acknowledgments: * This product includes software developed by Jason R. Thorpe * for And Communications, http://www.and.com/ * 4. The name of the author may not be used to endorse or promote products *************** *** 34,40 **** #include <sys/param.h> #include <sys/ioctl.h> ! #include <sys/chio.h> #include <err.h> #include <errno.h> #include <fcntl.h> --- 34,40 ---- #include <sys/param.h> #include <sys/ioctl.h> ! #include <sys/chio.h> #include <err.h> #include <errno.h> #include <fcntl.h> *************** *** 47,52 **** --- 47,53 ---- #include "defs.h" #include "pathnames.h" + int main __P((int, char *[])); static void usage __P((void)); static void cleanup __P((void)); static int parse_element_type __P((char *)); *************** *** 62,67 **** --- 63,69 ---- static int do_getpicker __P((char *, int, char **)); static int do_setpicker __P((char *, int, char **)); static int do_status __P((char *, int, char **)); + static int do_ielem __P((char *, int, char **)); /* Valid changer element types. */ const struct element_type elements[] = { *************** *** 81,86 **** --- 83,89 ---- { "getpicker", do_getpicker }, { "setpicker", do_setpicker }, { "status", do_status }, + { "ielem", do_ielem }, { NULL, 0 }, }; *************** *** 98,104 **** int main(argc, argv) int argc; ! char **argv; { int ch, i; --- 101,107 ---- int main(argc, argv) int argc; ! char *argv[]; { int ch, i; *************** *** 135,146 **** --- 138,157 ---- for (i = 0; commands[i].cc_name != NULL; ++i) if (strcmp(*argv, commands[i].cc_name) == 0) break; + if (commands[i].cc_name == NULL) { + /* look for abbreviation */ + for (i = 0; commands[i].cc_name != NULL; ++i) + if (strncmp(*argv, commands[i].cc_name, + strlen(*argv)) == 0) + break; + } if (commands[i].cc_name == NULL) errx(1, "unknown command: %s", *argv); /* Skip over the command name and call handler. */ ++argv; --argc; exit ((*commands[i].cc_handler)(commands[i].cc_name, argc, argv)); + /* NOTREACHED */ } static int *************** *** 166,172 **** warnx("%s: too many arguments", cname); goto usage; } ! bzero(&cmd, sizeof(cmd)); /* <from ET> */ cmd.cm_fromtype = parse_element_type(*argv); --- 177,183 ---- warnx("%s: too many arguments", cname); goto usage; } ! (void) memset(&cmd, 0, sizeof(cmd)); /* <from ET> */ cmd.cm_fromtype = parse_element_type(*argv); *************** *** 206,212 **** return (0); usage: ! fprintf(stderr, "usage: chio %s " "<from ET> <from EU> <to ET> <to EU> [inv]\n", cname); return (1); } --- 217,223 ---- return (0); usage: ! (void) fprintf(stderr, "usage: chio %s " "<from ET> <from EU> <to ET> <to EU> [inv]\n", cname); return (1); } *************** *** 234,240 **** warnx("%s: too many arguments", cname); goto usage; } ! bzero(&cmd, sizeof(cmd)); /* <src ET> */ cmd.ce_srctype = parse_element_type(*argv); --- 245,251 ---- warnx("%s: too many arguments", cname); goto usage; } ! (void) memset(&cmd, 0, sizeof(cmd)); /* <src ET> */ cmd.ce_srctype = parse_element_type(*argv); *************** *** 299,305 **** return (0); usage: ! fprintf(stderr, "usage: chio %s <src ET> <src EU> <dst1 ET> <dst1 EU>\n" " [<dst2 ET> <dst2 EU>] [inv1] [inv2]\n", cname); return (1); --- 310,316 ---- return (0); usage: ! (void) fprintf(stderr, "usage: chio %s <src ET> <src EU> <dst1 ET> <dst1 EU>\n" " [<dst2 ET> <dst2 EU>] [inv1] [inv2]\n", cname); return (1); *************** *** 328,334 **** warnx("%s: too many arguments", cname); goto usage; } ! bzero(&cmd, sizeof(cmd)); /* <to ET> */ cmd.cp_type = parse_element_type(*argv); --- 339,345 ---- warnx("%s: too many arguments", cname); goto usage; } ! (void) memset(&cmd, 0, sizeof(cmd)); /* <to ET> */ cmd.cp_type = parse_element_type(*argv); *************** *** 360,369 **** return (0); usage: ! fprintf(stderr, "usage: chio %s <to ET> <to EU> [inv]\n", cname); return (1); } static int do_params(cname, argc, argv) char *cname; --- 371,381 ---- return (0); usage: ! (void) fprintf(stderr, "usage: chio %s <to ET> <to EU> [inv]\n", cname); return (1); } + /* ARGSUSED */ static int do_params(cname, argc, argv) char *cname; *************** *** 374,405 **** /* No arguments to this command. */ if (argc) { ! warnx("%s: no arguements expected", cname); goto usage; } /* Get params from changer and display them. */ ! bzero(&data, sizeof(data)); if (ioctl(changer_fd, CHIOGPARAMS, (char *)&data)) err(1, "%s: CHIOGPARAMS", changer_name); ! printf("%s: %d slot%s, %d drive%s, %d picker%s", changer_name, data.cp_nslots, (data.cp_nslots > 1) ? "s" : "", data.cp_ndrives, (data.cp_ndrives > 1) ? "s" : "", data.cp_npickers, (data.cp_npickers > 1) ? "s" : ""); if (data.cp_nportals) ! printf(", %d portal%s", data.cp_nportals, (data.cp_nportals > 1) ? "s" : ""); ! printf("\n%s: current picker: %d\n", changer_name, data.cp_curpicker); return (0); usage: ! fprintf(stderr, "usage: chio %s\n", cname); return (1); } static int do_getpicker(cname, argc, argv) char *cname; --- 386,419 ---- /* No arguments to this command. */ if (argc) { ! warnx("%s: no arguments expected", cname); goto usage; } /* Get params from changer and display them. */ ! (void) memset(&data, 0, sizeof(data)); if (ioctl(changer_fd, CHIOGPARAMS, (char *)&data)) err(1, "%s: CHIOGPARAMS", changer_name); ! (void) printf("%s: %d slot%s, %d drive%s, %d picker%s", changer_name, data.cp_nslots, (data.cp_nslots > 1) ? "s" : "", data.cp_ndrives, (data.cp_ndrives > 1) ? "s" : "", data.cp_npickers, (data.cp_npickers > 1) ? "s" : ""); if (data.cp_nportals) ! (void) printf(", %d portal%s", data.cp_nportals, (data.cp_nportals > 1) ? "s" : ""); ! (void) printf("\n%s: current picker: %d\n", changer_name, ! data.cp_curpicker); return (0); usage: ! (void) fprintf(stderr, "usage: chio %s\n", cname); return (1); } + /* ARGSUSED */ static int do_getpicker(cname, argc, argv) char *cname; *************** *** 418,429 **** if (ioctl(changer_fd, CHIOGPICKER, (char *)&picker)) err(1, "%s: CHIOGPICKER", changer_name); ! printf("%s: current picker: %d\n", changer_name, picker); return (0); usage: ! fprintf(stderr, "usage: chio %s\n", cname); return (1); } --- 432,443 ---- if (ioctl(changer_fd, CHIOGPICKER, (char *)&picker)) err(1, "%s: CHIOGPICKER", changer_name); ! (void) printf("%s: current picker: %d\n", changer_name, picker); return (0); usage: ! (void) fprintf(stderr, "usage: chio %s\n", cname); return (1); } *************** *** 452,458 **** return (0); usage: ! fprintf(stderr, "usage: chio %s <picker>\n", cname); return (1); } --- 466,472 ---- return (0); usage: ! (void) fprintf(stderr, "usage: chio %s <picker>\n", cname); return (1); } *************** *** 465,476 **** struct changer_element_status cmd; struct changer_params data; u_int8_t *statusp; ! int i, count, chet, schet, echet; char *description; - count = 0; - description = NULL; - /* * On a status command, we expect the following: * --- 479,488 ---- struct changer_element_status cmd; struct changer_params data; u_int8_t *statusp; ! int i, chet, schet, echet; ! size_t count; char *description; /* * On a status command, we expect the following: * *************** *** 490,496 **** * Get params from changer. Specifically, we need the element * counts. */ ! bzero(&data, sizeof(data)); if (ioctl(changer_fd, CHIOGPARAMS, (char *)&data)) err(1, "%s: CHIOGPARAMS", changer_name); --- 502,508 ---- * Get params from changer. Specifically, we need the element * counts. */ ! (void) memset(&data, 0, sizeof(data)); if (ioctl(changer_fd, CHIOGPARAMS, (char *)&data)) err(1, "%s: CHIOGPARAMS", changer_name); *************** *** 522,534 **** count = data.cp_ndrives; description = "drive"; break; } if (count == 0) { if (argc == 0) continue; else { ! printf("%s: no %s elements\n", changer_name, description); return (0); } --- 534,551 ---- count = data.cp_ndrives; description = "drive"; break; + + default: + /* To appease gcc -Wuninitialized. */ + count = 0; + description = NULL; } if (count == 0) { if (argc == 0) continue; else { ! (void) printf("%s: no %s elements\n", changer_name, description); return (0); } *************** *** 538,545 **** if ((statusp = (u_int8_t *)malloc(count)) == NULL) errx(1, "can't allocate status storage"); ! bzero(statusp, count); ! bzero(&cmd, sizeof(cmd)); cmd.ces_type = chet; cmd.ces_data = statusp; --- 555,562 ---- if ((statusp = (u_int8_t *)malloc(count)) == NULL) errx(1, "can't allocate status storage"); ! (void) memset(statusp, 0, count); ! (void) memset(&cmd, 0, sizeof(cmd)); cmd.ces_type = chet; cmd.ces_data = statusp; *************** *** 551,557 **** /* Dump the status for each element of this type. */ for (i = 0; i < count; ++i) { ! printf("%s %d: %s\n", description, i, bits_to_string(statusp[i], CESTATUS_BITS)); } --- 568,574 ---- /* Dump the status for each element of this type. */ for (i = 0; i < count; ++i) { ! (void) printf("%s %d: %s\n", description, i, bits_to_string(statusp[i], CESTATUS_BITS)); } *************** *** 561,570 **** return (0); usage: ! fprintf(stderr, "usage: chio %s [<element type>]\n", cname); return (1); } static int parse_element_type(cp) char *cp; --- 578,601 ---- return (0); usage: ! (void) fprintf(stderr, "usage: chio %s [<element type>]\n", cname); return (1); } + /* ARGSUSED */ + static int + do_ielem(cname, argc, argv) + char *cname; + int argc; + char **argv; + { + if (ioctl(changer_fd, CHIOIELEM, NULL)) + err(1, "%s: CHIOIELEM", changer_name); + + return (0); + } + + static int parse_element_type(cp) char *cp; *************** *** 576,581 **** --- 607,613 ---- return (elements[i].et_type); errx(1, "invalid element type `%s'", cp); + /* NOTREACHED */ } static int *************** *** 603,608 **** --- 635,641 ---- return (val); errx(1, "invalid modifier `%s'", cp); + /* NOTREACHED */ } static int *************** *** 628,634 **** static char buf[128]; bp = buf; ! bzero(buf, sizeof(buf)); for (sep = '<'; (f = *cp++) != 0; cp = np) { for (np = cp; *np >= ' ';) --- 661,667 ---- static char buf[128]; bp = buf; ! (void) memset(buf, 0, sizeof(buf)); for (sep = '<'; (f = *cp++) != 0; cp = np) { for (np = cp; *np >= ' ';) *************** *** 636,642 **** if ((v & (1 << (f - 1))) == 0) continue; bp += snprintf(bp, sizeof(buf) - (bp - &buf[0]), ! "%c%.*s", sep, np - cp, cp); sep = ','; } if (sep != '<') --- 669,675 ---- if ((v & (1 << (f - 1))) == 0) continue; bp += snprintf(bp, sizeof(buf) - (bp - &buf[0]), ! "%c%.*s", sep, (int)(long)(np - cp), cp); sep = ','; } if (sep != '<') *************** *** 648,654 **** static void cleanup() { - /* Simple enough... */ (void)close(changer_fd); } --- 681,686 ---- diff -c -r /usr/src/bin/chio/defs.h /usr/local/src/bin/chio/defs.h *** /usr/src/bin/chio/defs.h Thu Mar 6 09:30:06 1997 --- /usr/local/src/bin/chio/defs.h Sun Feb 1 20:18:06 1998 *************** *** 13,19 **** * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software ! * must display the following acknowledgements: * This product includes software developed by Jason R. Thorpe * for And Communications, http://www.and.com/ * 4. The name of the author may not be used to endorse or promote products --- 13,19 ---- * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software ! * must display the following acknowledgments: * This product includes software developed by Jason R. Thorpe * for And Communications, http://www.and.com/ * 4. The name of the author may not be used to endorse or promote products diff -c -r /usr/src/bin/chio/pathnames.h /usr/local/src/bin/chio/pathnames.h *** /usr/src/bin/chio/pathnames.h Thu Mar 6 09:30:06 1997 --- /usr/local/src/bin/chio/pathnames.h Mon Feb 2 19:23:06 1998 *************** *** 13,19 **** * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software ! * must display the following acknowledgements: * This product includes software developed by Jason R. Thorpe * for And Communications, http://www.and.com/ * 4. The name of the author may not be used to endorse or promote products --- 13,19 ---- * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software ! * must display the following acknowledgments: * This product includes software developed by Jason R. Thorpe * for And Communications, http://www.and.com/ * 4. The name of the author may not be used to endorse or promote products *** /usr/src/sys/sys/chio.h Tue Mar 11 13:38:02 1997 --- /usr/local/src/sys/sys/chio.h Mon Feb 2 20:15:20 1998 *************** *** 151,156 **** --- 151,157 ---- #define CHIOGPICKER _IOR('c', 0x04, int) #define CHIOSPICKER _IOW('c', 0x05, int) #define CHIOGPARAMS _IOR('c', 0x06, struct changer_params) + #define CHIOIELEM _IO('c', 0x07) #define CHIOGSTATUS _IOW('c', 0x08, struct changer_element_status) #endif /* !_SYS_CHIO_H_ */ >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199802110505.VAA19832>