aboutsummaryrefslogtreecommitdiffstats
path: root/todo/putback.c
diff options
context:
space:
mode:
Diffstat (limited to 'todo/putback.c')
-rw-r--r--todo/putback.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/todo/putback.c b/todo/putback.c
new file mode 100644
index 0000000..89c54e2
--- /dev/null
+++ b/todo/putback.c
@@ -0,0 +1,100 @@
+/*
+ * program putback
+ *
+ * puts back media in scsi-changer
+ *
+ * usage: /usr/sbin/putback
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <ctype.h>
+#include <signal.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include <linux/chio.h>
+
+#define PROG "putback"
+#define CHANGER "/dev/sch0"
+
+#define DEBUG 0 /* set to 1 for debug output */
+
+/* ---------------------------------------------------------------------- */
+
+int main(int argc, char *argv[])
+{
+ struct changer_params params;
+ struct changer_get_element *dt;
+ struct changer_move move;
+ char *h;
+ int fd,i,drive,cside;
+
+ if (argc != 1) {
+ fprintf(stderr,"Usage: %s\n",argv[0]);
+ exit(1);
+ }
+
+ if (-1 == (fd = open(CHANGER,O_RDONLY))) {
+ perror(PROG ": open " CHANGER);
+ exit(1);
+ }
+
+ /* read changer status information */
+ if (ioctl(fd,CHIOGPARAMS,&params)) {
+ perror(PROG ": ioctl CHIOGPARAMS");
+ exit(1);
+ }
+#if DEBUG
+ fprintf(stderr,PROG ": %d drives, %d slots\n",
+ params.cp_ndrives,params.cp_nslots);
+#endif
+
+ dt = malloc(sizeof(struct changer_get_element)*params.cp_ndrives);
+ for (i = 0; i < params.cp_ndrives; i++) {
+ dt[i].cge_type=CHET_DT;
+ dt[i].cge_unit=i;
+ if (ioctl(fd,CHIOGELEM,dt+i)) {
+ fprintf(stderr,PROG ":ioctl CHIOGELEM mt %d: %s\n",
+ i,strerror(errno));
+ exit(1);
+ }
+ if (NULL != (h = strchr(dt[i].cge_pvoltag,' '))) *h = '\0';
+ if (NULL != (h = strchr(dt[i].cge_avoltag,' '))) *h = '\0';
+ }
+
+
+ for (drive=0; drive<params.cp_ndrives; drive++) {
+
+ if (dt[drive].cge_status & CESTATUS_FULL) {
+ /* put back the old media ... */
+ if (!(dt[drive].cge_flags & CGE_SRC)) {
+ fprintf(stderr,PROG ": source element for drive %d unknown\n",
+ drive);
+ exit(1);
+ }
+ memset(&move,0,sizeof(struct changer_move));
+ move.cm_totype = dt[drive].cge_srctype;
+ move.cm_tounit = dt[drive].cge_srcunit;
+ move.cm_fromtype = CHET_DT;
+ move.cm_fromunit = drive;
+ cside = ((dt[drive].cge_flags & CGE_INVERT) == CGE_INVERT);
+ move.cm_flags = (cside == 0) ? 0 : CM_INVERT;
+ if (ioctl(fd,CHIOMOVE,&move)) {
+ fprintf(stderr,PROG ": ioctl MOVE (unload): %s\n",
+ sys_errlist[errno]);
+ exit(1);
+ }
+ }
+ }
+
+ exit(0);
+}
+
+