[stgt] [PATCH 02/15] move ssc tools to utils to usr

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Sun Oct 5 16:37:32 CEST 2008


We have tgtadm tool in usr so it's fine to have other tools in usr
too. We might rename dump_tape and mktape but this leaves them alone.

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 .gitignore        |    2 +
 usr/Makefile      |    2 +-
 usr/dump_tape.c   |  209 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 usr/mktape.c      |  192 ++++++++++++++++++++++++++++++++++++++++++++++++
 utils/Makefile    |   34 ---------
 utils/dump_tape.c |  209 -----------------------------------------------------
 utils/mktape.c    |  192 ------------------------------------------------
 7 files changed, 404 insertions(+), 436 deletions(-)
 create mode 100644 usr/dump_tape.c
 create mode 100644 usr/mktape.c
 delete mode 100644 utils/Makefile
 delete mode 100644 utils/dump_tape.c
 delete mode 100644 utils/mktape.c

diff --git a/.gitignore b/.gitignore
index c4b744a..456009a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,5 @@ GSYMS
 #
 usr/tgtd
 usr/tgtadm
+usr/dump_tape
+usr/mktape
diff --git a/usr/Makefile b/usr/Makefile
index a59364b..98845a2 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -54,7 +54,7 @@ CFLAGS += -g -O2 -Wall -Wstrict-prototypes -fPIC
 
 LIBS += -lpthread
 
-PROGRAMS += tgtd tgtadm
+PROGRAMS += tgtd tgtadm mktape dump_tape
 SCRIPTS += ../scripts/tgt-setup-lun ../scripts/tgt-admin
 TGTD_OBJS += tgtd.o mgmt.o target.o scsi.o log.o driver.o util.o work.o \
 		parser.o spc.o sbc.o mmc.o osd.o scc.o smc.o ssc.o bs_ssc.o \
diff --git a/usr/dump_tape.c b/usr/dump_tape.c
new file mode 100644
index 0000000..ef6b6c3
--- /dev/null
+++ b/usr/dump_tape.c
@@ -0,0 +1,209 @@
+/*
+ *	Dump headers of 'tape' datafile
+ *
+ * Copyright (C) 2008 Mark Harvey markh794 at gmail.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <inttypes.h>
+#include <time.h>
+#include "scsi.h"
+#include "media.h"
+#include "ssc.h"
+#include "bs_ssc.h"
+
+void print_current_header(struct blk_header *pos)
+{
+	if (pos->a != 'A')
+		printf("head sanity check failed\n");
+	if (pos->z != 'Z')
+		printf("tail sanity check failed\n");
+
+	switch (pos->blk_type) {
+	case BLK_UNCOMPRESS_DATA:
+		printf(" Uncompressed data");
+		break;
+	case BLK_FILEMARK:
+		printf("         Filemark");
+		break;
+	case BLK_BOT:
+		printf("Beginning of Tape");
+		break;
+	case BLK_EOD:
+		printf("      End of Data");
+		break;
+	case BLK_NOOP:
+		printf("      No Operation");
+		break;
+	default:
+		printf("      Unknown type");
+		break;
+	}
+	if (pos->blk_type == BLK_BOT)
+		printf("(%d): Capacity %d MB, Blk No.: %" PRId64
+		", prev %" PRId64 ", curr %" PRId64 ", next %" PRId64 "\n",
+			pos->blk_type,
+			pos->blk_sz,
+			pos->blk_num,
+			(uint64_t)pos->prev,
+			(uint64_t)pos->curr,
+			(uint64_t)pos->next);
+	else
+		printf("(%d): Blk No. %" PRId64 ", prev %" PRId64 ""
+			", curr %" PRId64 ",  next %" PRId64 ", sz %d\n",
+			pos->blk_type,
+			pos->blk_num,
+			(uint64_t)pos->prev,
+			(uint64_t)pos->curr,
+			(uint64_t)pos->next,
+			pos->ondisk_sz);
+}
+
+int skip_to_next_header(int fd, struct blk_header *pos)
+{
+	loff_t nread;
+
+	nread = lseek64(fd, (uint64_t)pos->next, SEEK_SET);
+	if ((uint64_t)pos->next != nread) {
+		printf("Error while seeking to next header\n");
+		return -1;
+	}
+	nread = read(fd, pos, sizeof(struct blk_header));
+	if (nread < sizeof(struct blk_header)) {
+		printf("Could not read complete blk header - short read!!\n");
+		return -1;
+	}
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	int ofp;
+	char *progname;
+	char datafile[1024] = "";
+	loff_t	nread;
+	struct MAM mam;
+	struct blk_header current_position;
+	time_t t;
+	int a;
+	unsigned char *p;
+
+	progname = argv[0];
+
+	if (argc < 2) {
+		printf("Usage: %s -f <media>\n", progname);
+		exit(1);
+	}
+
+	while (argc > 0) {
+		if (argv[0][0] == '-') {
+			switch (argv[0][1]) {
+			case 'f':
+				if (argc > 1) {
+					strncpy(datafile, argv[1],
+							sizeof(datafile));
+				} else {
+					puts("    More args needed for -f\n");
+					exit(1);
+				}
+				break;
+			}
+		}
+		argv++;
+		argc--;
+	}
+
+	if (strlen(datafile) == 0) {
+		printf("Usage: %s -f <media>\n", progname);
+		exit(1);
+	}
+
+	ofp = open(datafile, O_RDWR|O_LARGEFILE);
+	if (ofp == -1) {
+		fprintf(stderr, "%s, ", datafile);
+		perror("Could not open");
+		exit(1);
+	}
+	nread = read(ofp, &current_position, sizeof(struct blk_header));
+	if (nread < sizeof(current_position)) {
+		perror("Could not read blk header");
+		exit(1);
+	}
+	nread = read(ofp, &mam, sizeof(struct MAM));
+	if (nread < (sizeof(struct MAM))) {
+		perror("Could not read MAM");
+		exit(1);
+	}
+	if (mam.tape_fmt_version != TGT_TAPE_VERSION) {
+		printf("Unknown media format version\n");
+		exit(1);
+	}
+
+	printf("Media     : %s\n", mam.barcode);
+	switch (mam.medium_type) {
+	case CART_UNSPECIFIED:
+		printf(" type     : Unspecified\n");
+		break;
+	case CART_DATA:
+		printf(" type     : Data\n");
+		break;
+	case CART_CLEAN:
+		printf(" type     : Cleaning\n");
+		break;
+	case CART_DIAGNOSTICS:
+		printf(" type     : Diagnostics\n");
+		break;
+	case CART_WORM:
+		printf(" type     : WORM\n");
+		break;
+	case CART_MICROCODE:
+		printf(" type     : Microcode\n");
+		break;
+	default:
+		printf(" type     : Unknown\n");
+	}
+	printf("Media serial number : %s, ", mam.medium_serial_number);
+
+	for (a = strlen((const char *)mam.medium_serial_number); a > 0; a--)
+		if (mam.medium_serial_number[a] == '_')
+			break;
+	if (a) {
+		a++;
+		p = &mam.medium_serial_number[a];
+		t = atoll((const char *)p);
+		printf("created %s", ctime(&t));
+	}
+	printf("\n");
+
+	print_current_header(&current_position);
+	while (current_position.blk_type != BLK_EOD) {
+		nread = skip_to_next_header(ofp, &current_position);
+		if (nread == -1)
+			break;
+		print_current_header(&current_position);
+	}
+
+	return (0);
+}
diff --git a/usr/mktape.c b/usr/mktape.c
new file mode 100644
index 0000000..1abf948
--- /dev/null
+++ b/usr/mktape.c
@@ -0,0 +1,192 @@
+/*
+ *	Create blank media files for bs_tape backing store
+ *
+ * Copyright (C) 2008 Mark Harvey markh794 at gmail.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <syslog.h>
+#include <string.h>
+#include <time.h>
+#include <inttypes.h>
+#include "media.h"
+#include "bs_ssc.h"
+#include "ssc.h"
+
+const char *mktape_version = "0.01";
+
+void usage(char *progname)
+{
+
+	printf("Usage: %s -m barcode -s size -t type\n", progname);
+	printf("       Where 'size' is in Megabytes\n");
+	printf("             'type' is data | clean | WORM\n");
+	printf("             'barcode' is a string of chars\n\n");
+}
+
+int main(int argc, char *argv[])
+{
+	int file;
+	struct blk_header h;
+	struct MAM mam;
+	uint8_t current_media[1024];
+	long nwrite;
+	char *progname = argv[0];
+	char *barcode = NULL;
+	char *media_type = NULL;
+	char *media_capacity = NULL;
+	uint32_t size;
+
+	if (argc < 2) {
+		usage(progname);
+		exit(1);
+	}
+
+	while (argc > 0) {
+		if (argv[0][0] == '-') {
+			switch (argv[0][1]) {
+			case 'm':
+				if (argc > 1) {
+					barcode = argv[1];
+				} else {
+					puts("    More args needed for -m\n");
+					exit(1);
+				}
+				break;
+			case 's':
+				if (argc > 1) {
+					media_capacity = argv[1];
+				} else {
+					puts("    More args needed for -s\n");
+					exit(1);
+				}
+				break;
+			case 't':
+				if (argc > 1) {
+					media_type = argv[1];
+				} else {
+					puts("    More args needed for -t\n");
+					exit(1);
+				}
+				break;
+			case 'V':
+				printf("%s: version %s\n",
+						progname, mktape_version);
+				break;
+			}
+		}
+		argv++;
+		argc--;
+	}
+
+	if (barcode == NULL) {
+		usage(progname);
+		exit(1);
+	}
+	if (media_capacity == NULL) {
+		usage(progname);
+		exit(1);
+	}
+	if (media_type == NULL) {
+		usage(progname);
+		exit(1);
+	}
+
+	sscanf(media_capacity, "%d", &size);
+	if (size == 0)
+		size = 8000;
+
+	h.a = 'A';
+	h.z = 'Z';
+	h.blk_type = BLK_BOT;
+	h.blk_num = 0;
+	h.blk_sz = size;
+	h.prev = 0;
+	h.curr = 0;
+	h.next = sizeof(mam) + sizeof(h);
+
+	printf("blk_sz: %d, next %" PRId64 ", %" PRId64 "\n",
+				h.blk_sz, h.next, h.next);
+	printf("Sizeof(mam): %" PRId64 ", sizeof(h): %" PRId64 "\n",
+			(uint64_t)sizeof(mam), (uint64_t)sizeof(h));
+	memset((uint8_t *)&mam, 0, sizeof(mam));
+
+	mam.tape_fmt_version = 2;
+	mam.max_capacity = size * 1048576;
+	mam.remaining_capacity = size * 1048576;
+	mam.MAM_space_remaining = sizeof(mam.vendor_unique);
+	mam.medium_length = 384;	/* 384 tracks */
+	mam.medium_width = 127;		/* 127 x tenths of mm (12.7 mm) */
+	memcpy(&mam.medium_manufacturer, "Foo     ", 8);
+	memcpy(&mam.application_vendor, "Bar     ", 8);
+
+	if (!strncmp("clean", media_type, 5)) {
+		mam.medium_type = CART_CLEAN;
+		mam.medium_type_information = 20; /* Max cleaning loads */
+	} else if (!strncmp("WORM", media_type, 4)) {
+		mam.medium_type = CART_WORM;
+	} else {
+		mam.medium_type = CART_DATA;
+	}
+
+	sprintf((char *)mam.medium_serial_number, "%s_%d",
+					barcode, (int)time(NULL));
+	sprintf((char *)mam.barcode, "%-31s", barcode);
+
+	sprintf((char *)current_media, "%s", barcode);
+	syslog(LOG_DAEMON|LOG_INFO, "%s being created", current_media);
+	file = creat((char *)current_media, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+	if (file == -1) {
+		perror("Failed creating file");
+		exit(2);
+	}
+	nwrite = write(file, &h, sizeof(h));
+	if (nwrite <= 0) {
+		perror("Unable to write header");
+		exit(1);
+	}
+	nwrite = write(file, &mam, sizeof(mam));
+	if (nwrite <= 0) {
+		perror("Unable to write MAM");
+		exit(1);
+	}
+	memset(&h, 0, sizeof(h));
+	h.a = 'A';
+	h.z = 'Z';
+	h.blk_type = BLK_EOD;
+	h.blk_num = 1;
+	h.prev = 0;
+	h.next = lseek64(file, 0, SEEK_CUR);
+	h.curr = h.next;
+
+	nwrite = write(file, &h, sizeof(h));
+	if (nwrite <= 0) {
+		perror("Unable to write header");
+		exit(1);
+	}
+	close(file);
+
+exit(0);
+}
+
diff --git a/utils/Makefile b/utils/Makefile
deleted file mode 100644
index fbb47f1..0000000
--- a/utils/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
-# LIBS := -L. -L.. -L../lib
-INCLUDES += -I../include -I../usr
-
-INCLUDES += -I.
-CFLAGS += -Wall -g -O2 -Wstrict-prototypes -fPIC -D_LARGEFILE64_SOURCE $(INCLUDES)
-
-PROGRAMS += mktape dump_tape
-MKTAPE_OBJS += mktape.o
-DUMP_TAPE_OBJS += dump_tape.o
-
-.PHONY: all
-all: $(PROGRAMS)
-
-mktape: $(MKTAPE_OBJS)
-	$(CC) $^ -o $@ $(LIBS)
-
--include mktape.d
-
-dump_tape: $(DUMP_TAPE_OBJS)
-	$(CC) $^ -o $@ $(LIBS)
-
--include dump_tape.d
-
-%.o: %c
-	$(CC) -c $(CFLAGS) $*.c -o $*.o
-	@$(CC) -MM $(CFLAGS) -MF $*.d -MT $*.o $*.c
-
-.PHONY: install
-install: $(PROGRAMS)
-	install -m 0755 $(PROGRAMS) $(DESTDIR)/usr/bin
-
-.PHONY: clean
-clean:
-	rm -f *.o $(PROGRAMS)
diff --git a/utils/dump_tape.c b/utils/dump_tape.c
deleted file mode 100644
index ef6b6c3..0000000
--- a/utils/dump_tape.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- *	Dump headers of 'tape' datafile
- *
- * Copyright (C) 2008 Mark Harvey markh794 at gmail.com
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <inttypes.h>
-#include <time.h>
-#include "scsi.h"
-#include "media.h"
-#include "ssc.h"
-#include "bs_ssc.h"
-
-void print_current_header(struct blk_header *pos)
-{
-	if (pos->a != 'A')
-		printf("head sanity check failed\n");
-	if (pos->z != 'Z')
-		printf("tail sanity check failed\n");
-
-	switch (pos->blk_type) {
-	case BLK_UNCOMPRESS_DATA:
-		printf(" Uncompressed data");
-		break;
-	case BLK_FILEMARK:
-		printf("         Filemark");
-		break;
-	case BLK_BOT:
-		printf("Beginning of Tape");
-		break;
-	case BLK_EOD:
-		printf("      End of Data");
-		break;
-	case BLK_NOOP:
-		printf("      No Operation");
-		break;
-	default:
-		printf("      Unknown type");
-		break;
-	}
-	if (pos->blk_type == BLK_BOT)
-		printf("(%d): Capacity %d MB, Blk No.: %" PRId64
-		", prev %" PRId64 ", curr %" PRId64 ", next %" PRId64 "\n",
-			pos->blk_type,
-			pos->blk_sz,
-			pos->blk_num,
-			(uint64_t)pos->prev,
-			(uint64_t)pos->curr,
-			(uint64_t)pos->next);
-	else
-		printf("(%d): Blk No. %" PRId64 ", prev %" PRId64 ""
-			", curr %" PRId64 ",  next %" PRId64 ", sz %d\n",
-			pos->blk_type,
-			pos->blk_num,
-			(uint64_t)pos->prev,
-			(uint64_t)pos->curr,
-			(uint64_t)pos->next,
-			pos->ondisk_sz);
-}
-
-int skip_to_next_header(int fd, struct blk_header *pos)
-{
-	loff_t nread;
-
-	nread = lseek64(fd, (uint64_t)pos->next, SEEK_SET);
-	if ((uint64_t)pos->next != nread) {
-		printf("Error while seeking to next header\n");
-		return -1;
-	}
-	nread = read(fd, pos, sizeof(struct blk_header));
-	if (nread < sizeof(struct blk_header)) {
-		printf("Could not read complete blk header - short read!!\n");
-		return -1;
-	}
-	return 0;
-}
-
-int main(int argc, char *argv[])
-{
-	int ofp;
-	char *progname;
-	char datafile[1024] = "";
-	loff_t	nread;
-	struct MAM mam;
-	struct blk_header current_position;
-	time_t t;
-	int a;
-	unsigned char *p;
-
-	progname = argv[0];
-
-	if (argc < 2) {
-		printf("Usage: %s -f <media>\n", progname);
-		exit(1);
-	}
-
-	while (argc > 0) {
-		if (argv[0][0] == '-') {
-			switch (argv[0][1]) {
-			case 'f':
-				if (argc > 1) {
-					strncpy(datafile, argv[1],
-							sizeof(datafile));
-				} else {
-					puts("    More args needed for -f\n");
-					exit(1);
-				}
-				break;
-			}
-		}
-		argv++;
-		argc--;
-	}
-
-	if (strlen(datafile) == 0) {
-		printf("Usage: %s -f <media>\n", progname);
-		exit(1);
-	}
-
-	ofp = open(datafile, O_RDWR|O_LARGEFILE);
-	if (ofp == -1) {
-		fprintf(stderr, "%s, ", datafile);
-		perror("Could not open");
-		exit(1);
-	}
-	nread = read(ofp, &current_position, sizeof(struct blk_header));
-	if (nread < sizeof(current_position)) {
-		perror("Could not read blk header");
-		exit(1);
-	}
-	nread = read(ofp, &mam, sizeof(struct MAM));
-	if (nread < (sizeof(struct MAM))) {
-		perror("Could not read MAM");
-		exit(1);
-	}
-	if (mam.tape_fmt_version != TGT_TAPE_VERSION) {
-		printf("Unknown media format version\n");
-		exit(1);
-	}
-
-	printf("Media     : %s\n", mam.barcode);
-	switch (mam.medium_type) {
-	case CART_UNSPECIFIED:
-		printf(" type     : Unspecified\n");
-		break;
-	case CART_DATA:
-		printf(" type     : Data\n");
-		break;
-	case CART_CLEAN:
-		printf(" type     : Cleaning\n");
-		break;
-	case CART_DIAGNOSTICS:
-		printf(" type     : Diagnostics\n");
-		break;
-	case CART_WORM:
-		printf(" type     : WORM\n");
-		break;
-	case CART_MICROCODE:
-		printf(" type     : Microcode\n");
-		break;
-	default:
-		printf(" type     : Unknown\n");
-	}
-	printf("Media serial number : %s, ", mam.medium_serial_number);
-
-	for (a = strlen((const char *)mam.medium_serial_number); a > 0; a--)
-		if (mam.medium_serial_number[a] == '_')
-			break;
-	if (a) {
-		a++;
-		p = &mam.medium_serial_number[a];
-		t = atoll((const char *)p);
-		printf("created %s", ctime(&t));
-	}
-	printf("\n");
-
-	print_current_header(&current_position);
-	while (current_position.blk_type != BLK_EOD) {
-		nread = skip_to_next_header(ofp, &current_position);
-		if (nread == -1)
-			break;
-		print_current_header(&current_position);
-	}
-
-	return (0);
-}
diff --git a/utils/mktape.c b/utils/mktape.c
deleted file mode 100644
index 1abf948..0000000
--- a/utils/mktape.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- *	Create blank media files for bs_tape backing store
- *
- * Copyright (C) 2008 Mark Harvey markh794 at gmail.com
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <syslog.h>
-#include <string.h>
-#include <time.h>
-#include <inttypes.h>
-#include "media.h"
-#include "bs_ssc.h"
-#include "ssc.h"
-
-const char *mktape_version = "0.01";
-
-void usage(char *progname)
-{
-
-	printf("Usage: %s -m barcode -s size -t type\n", progname);
-	printf("       Where 'size' is in Megabytes\n");
-	printf("             'type' is data | clean | WORM\n");
-	printf("             'barcode' is a string of chars\n\n");
-}
-
-int main(int argc, char *argv[])
-{
-	int file;
-	struct blk_header h;
-	struct MAM mam;
-	uint8_t current_media[1024];
-	long nwrite;
-	char *progname = argv[0];
-	char *barcode = NULL;
-	char *media_type = NULL;
-	char *media_capacity = NULL;
-	uint32_t size;
-
-	if (argc < 2) {
-		usage(progname);
-		exit(1);
-	}
-
-	while (argc > 0) {
-		if (argv[0][0] == '-') {
-			switch (argv[0][1]) {
-			case 'm':
-				if (argc > 1) {
-					barcode = argv[1];
-				} else {
-					puts("    More args needed for -m\n");
-					exit(1);
-				}
-				break;
-			case 's':
-				if (argc > 1) {
-					media_capacity = argv[1];
-				} else {
-					puts("    More args needed for -s\n");
-					exit(1);
-				}
-				break;
-			case 't':
-				if (argc > 1) {
-					media_type = argv[1];
-				} else {
-					puts("    More args needed for -t\n");
-					exit(1);
-				}
-				break;
-			case 'V':
-				printf("%s: version %s\n",
-						progname, mktape_version);
-				break;
-			}
-		}
-		argv++;
-		argc--;
-	}
-
-	if (barcode == NULL) {
-		usage(progname);
-		exit(1);
-	}
-	if (media_capacity == NULL) {
-		usage(progname);
-		exit(1);
-	}
-	if (media_type == NULL) {
-		usage(progname);
-		exit(1);
-	}
-
-	sscanf(media_capacity, "%d", &size);
-	if (size == 0)
-		size = 8000;
-
-	h.a = 'A';
-	h.z = 'Z';
-	h.blk_type = BLK_BOT;
-	h.blk_num = 0;
-	h.blk_sz = size;
-	h.prev = 0;
-	h.curr = 0;
-	h.next = sizeof(mam) + sizeof(h);
-
-	printf("blk_sz: %d, next %" PRId64 ", %" PRId64 "\n",
-				h.blk_sz, h.next, h.next);
-	printf("Sizeof(mam): %" PRId64 ", sizeof(h): %" PRId64 "\n",
-			(uint64_t)sizeof(mam), (uint64_t)sizeof(h));
-	memset((uint8_t *)&mam, 0, sizeof(mam));
-
-	mam.tape_fmt_version = 2;
-	mam.max_capacity = size * 1048576;
-	mam.remaining_capacity = size * 1048576;
-	mam.MAM_space_remaining = sizeof(mam.vendor_unique);
-	mam.medium_length = 384;	/* 384 tracks */
-	mam.medium_width = 127;		/* 127 x tenths of mm (12.7 mm) */
-	memcpy(&mam.medium_manufacturer, "Foo     ", 8);
-	memcpy(&mam.application_vendor, "Bar     ", 8);
-
-	if (!strncmp("clean", media_type, 5)) {
-		mam.medium_type = CART_CLEAN;
-		mam.medium_type_information = 20; /* Max cleaning loads */
-	} else if (!strncmp("WORM", media_type, 4)) {
-		mam.medium_type = CART_WORM;
-	} else {
-		mam.medium_type = CART_DATA;
-	}
-
-	sprintf((char *)mam.medium_serial_number, "%s_%d",
-					barcode, (int)time(NULL));
-	sprintf((char *)mam.barcode, "%-31s", barcode);
-
-	sprintf((char *)current_media, "%s", barcode);
-	syslog(LOG_DAEMON|LOG_INFO, "%s being created", current_media);
-	file = creat((char *)current_media, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
-	if (file == -1) {
-		perror("Failed creating file");
-		exit(2);
-	}
-	nwrite = write(file, &h, sizeof(h));
-	if (nwrite <= 0) {
-		perror("Unable to write header");
-		exit(1);
-	}
-	nwrite = write(file, &mam, sizeof(mam));
-	if (nwrite <= 0) {
-		perror("Unable to write MAM");
-		exit(1);
-	}
-	memset(&h, 0, sizeof(h));
-	h.a = 'A';
-	h.z = 'Z';
-	h.blk_type = BLK_EOD;
-	h.blk_num = 1;
-	h.prev = 0;
-	h.next = lseek64(file, 0, SEEK_CUR);
-	h.curr = h.next;
-
-	nwrite = write(file, &h, sizeof(h));
-	if (nwrite <= 0) {
-		perror("Unable to write header");
-		exit(1);
-	}
-	close(file);
-
-exit(0);
-}
-
-- 
1.5.6.5

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list