[PATCH 1/1] enhance tgtimg to create media for DVD emulation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please find attached a patch to tgtimg and its manpage to describe the use of
tgtimg to create media for the dvd emulation.


regards
ronnie sahlberg

Attachment: 0001-Update-tgtimg-to-be-able-to-create-mediafiles-for-CD.patch.gz
Description: GNU Zip compressed data

From 4d61f7c291cbaca98eaa6c36bda78661a085c64b Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
Date: Fri, 2 Apr 2010 10:02:17 +1100
Subject: [PATCH] Update tgtimg to be able to create mediafiles for CD/DVD+R using
    tgtimg --op new --device-type cd --type dvd+r --file ./dvd.img

Update the manpage for tgtimg to describe this new functionality

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
---
 doc/htmlpages/tgtimg.8.html |   65 ++++++++++++++++++-------------
 doc/manpages/tgtimg.8       |   78 +++++++++++++++++++++++++-------------
 doc/tgtimg.8.xml            |   88 ++++++++++++++++++++++++++----------------
 usr/tgtimg.c                |   81 ++++++++++++++++++++++++++++++++++-----
 4 files changed, 214 insertions(+), 98 deletions(-)

diff --git a/doc/htmlpages/tgtimg.8.html b/doc/htmlpages/tgtimg.8.html
index 5c8fcb9..202473f 100644
--- a/doc/htmlpages/tgtimg.8.html
+++ b/doc/htmlpages/tgtimg.8.html
@@ -1,20 +1,35 @@
-<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>tgtimg</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en"><a name="tgtimg.8"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>tgtimg &#8212; Linux SCSI Target Framework Image File Utility</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p><code class="command">tgtimg --op new --device-type tape </code> <br><code class="command">--barcode &lt;code&gt; --size &lt;size&gt; --type &lt;type&gt; --file &lt;path&gt;</code> </p></div><div class="cmdsynopsis"><p><code class="command">tgtimg --op show --device-type tape --file=&lt;path&gt;</code> </p></div><div class="cmdsynopsis"><p><code class="command">tgtimg --help</code> </p></div></div><div class="refsect1" lang="en"><a name="id2475961"></a><h2>DESCRIPTION</h2><p>
-      tgtimg is a utility to create and manage the image files used by the
-      stgt tape emulation.
+<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>tgtimg</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en"><a name="tgtimg.8"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>tgtimg &#8212; Linux SCSI Target Framework Image File Utility</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p><code class="command">tgtimg</code>  [-o --op &lt;operation&gt;] [-Y --device-type &lt;device-type&gt;] [-b --barcode &lt;barcode&gt;] [-s --size &lt;size&gt;] [-t --type &lt;media-type&gt;] [-f --file &lt;path&gt;]</p></div><div class="cmdsynopsis"><p><code class="command">tgtimg --help</code> </p></div></div><div class="refsect1" lang="en"><a name="id2476001"></a><h2>DESCRIPTION</h2><p>
+      Tgtimg is a utility to create and manage the image files used by the 
+      TGTD device emulation.
     </p><p>
-      This command is used to initialize tape image files with the additional
+      This command is used to initialize device image files with the additional
       metadata, such as barcode, list of blocks, total size, etc that
-      the tape emulation of TGTD needs.
-    </p><p>
-      You must use this command to initialize a file so that TGTD will\
-      recognize it as a tape image.
-    </p></div><div class="refsect1" lang="en"><a name="id2475984"></a><h2>OPTIONS</h2><div class="variablelist"><dl><dt><span class="term"><code class="option">-h, --help</code></span></dt><dd><p>
+      the TGTD emulation needs.
+    </p></div><div class="refsect1" lang="en"><a name="id2476018"></a><h2>OPTIONS</h2><div class="variablelist"><pre class="screen">
+Supported device types are :
+    tape : to create media for a tape device
+    cd   : to create media for a dvd device
+      </pre><pre class="screen">
+Supported media types for tape devices are :
+    data  : create a normal data tape
+    clean : create a cleaning tape
+    worm  : create a worm
+
+Supported media types for cd devices are :
+    dvd+r : create a blank writeable DVD+R disk
+      </pre><dl><dt><span class="term"><code class="option">-h, --help</code></span></dt><dd><p>
 	    Show a help screen and exit.
           </p></dd><dt><span class="term"><code class="option">-o, --op {new|show}</code></span></dt><dd><p>
 	    Operation. Is either new to create a new image file or show to
 	    show the content of an existing image file.
           </p></dd><dt><span class="term"><code class="option">-Y, --device-type &lt;type&gt;</code></span></dt><dd><p>
-	    This specifies the type of image file. The only valid type is tape.
+	    This specifies the type of image file.
+          </p></dd><dt><span class="term"><code class="option">-t, --type &lt;media-type&gt;</code></span></dt><dd><p>
+	    When creating a new image, this specifies the type of media to
+	    emulate, normal data, cleaning image, or worm.
+          </p><p>
+	    Data is a normal tape to read/write to and probably what you 
+	    want to use.
           </p></dd><dt><span class="term"><code class="option">-b, --barcode &lt;barcode&gt;</code></span></dt><dd><p>
 	    When creating a new image, this argument specifies the barcode
 	    to use with this image file. Backup application software often
@@ -23,27 +38,23 @@
           </p></dd><dt><span class="term"><code class="option">-s, --size &lt;size&gt;</code></span></dt><dd><p>
 	    When creating a new image, this specifies the size in megabytes
 	    for the virtual tape image.
-          </p></dd><dt><span class="term"><code class="option">-t, --type {data|clean|worm}</code></span></dt><dd><p>
-	    When creating a new image, this specifies the type of media to
-	    emulate, normal data, cleaning image, or worm.
-          </p><p>
-	    Data is a normal tape to read/write to and probably what you
-	    want to use.
           </p></dd><dt><span class="term"><code class="option">-f, --file &lt;path&gt;</code></span></dt><dd><p>
 	    The filename of the image file.
-          </p></dd></dl></div></div><div class="refsect1" lang="en"><a name="id2476108"></a><h2>EXAMPLES</h2><p>
-      To create a new image
-      </p><pre class="screen">
-	tgtimg --op new --device-type tape --barcode 12345 --size 100 --type data --file /data/tape001.img
-      </pre><p>
-    </p><p>
+          </p></dd></dl></div></div><div class="refsect1" lang="en"><a name="id2476161"></a><h2>EXAMPLES</h2><p>
+      To create a new tape image
+    </p><pre class="screen">
+      tgtimg --op new --device-type tape --barcode 12345 --size 100 --type data --file /data/tape001.img
+    </pre><p>
       To view the content of an existing image
-      </p><pre class="screen">
-	tgtimg --op show --device-type tape --file /data/tape001.img
-      </pre><p>
-    </p></div><div class="refsect1" lang="en"><a name="id2476136"></a><h2>SEE ALSO</h2><p>
+    </p><pre class="screen">
+      tgtimg --op show --device-type tape --file /data/tape001.img
+    </pre><p>
+      To create a new blank DVD+R image
+    </p><pre class="screen">
+      tgtimg --op new --device-type cd --type dvd+r --file /data/dvd001.iso
+    </pre></div><div class="refsect1" lang="en"><a name="id2476201"></a><h2>SEE ALSO</h2><p>
       tgtd(8), tgtadm(8), tgt-admin(8), tgt-setup-lun(8).
       <a class="ulink" href="http://stgt.sourceforge.net/"; target="_top">http://stgt.sourceforge.net/</a>
-    </p></div><div class="refsect1" lang="en"><a name="id2476151"></a><h2>REPORTING BUGS</h2><p>
+    </p></div><div class="refsect1" lang="en"><a name="id2476215"></a><h2>REPORTING BUGS</h2><p>
       Report bugs to &lt;stgt@xxxxxxxxxxxxxxx&gt;
     </p></div></div></body></html>
diff --git a/doc/manpages/tgtimg.8 b/doc/manpages/tgtimg.8
index f46f32f..920562f 100644
--- a/doc/manpages/tgtimg.8
+++ b/doc/manpages/tgtimg.8
@@ -1,11 +1,11 @@
 .\"     Title: tgtimg
-.\"    Author:
+.\"    Author: 
 .\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
-.\"      Date: 03/04/2010
-.\"    Manual:
-.\"    Source:
+.\"      Date: 04/02/2010
+.\"    Manual: 
+.\"    Source: 
 .\"
-.TH "TGTIMG" "8" "03/04/2010" "" ""
+.TH "TGTIMG" "8" "04/02/2010" "" ""
 .\" disable hyphenation
 .nh
 .\" disable justification (adjust text to left margin only)
@@ -13,19 +13,15 @@
 .SH "NAME"
 tgtimg - Linux SCSI Target Framework Image File Utility
 .SH "SYNOPSIS"
-.HP 35
-\fBtgtimg \-\-op new \-\-device\-type tape \fR\fB\-\-barcode <code> \-\-size <size> \-\-type <type> \-\-file <path>\fR
-.HP 50
-\fBtgtimg \-\-op show \-\-device\-type tape \-\-file=<path>\fR
+.HP 7
+\fBtgtimg\fR [\-o\ \-\-op\ <operation>] [\-Y\ \-\-device\-type\ <device\-type>] [\-b\ \-\-barcode\ <barcode>] [\-s\ \-\-size\ <size>] [\-t\ \-\-type\ <media\-type>] [\-f\ \-\-file\ <path>]
 .HP 14
 \fBtgtimg \-\-help\fR
 .SH "DESCRIPTION"
 .PP
-tgtimg is a utility to create and manage the image files used by the stgt tape emulation\.
+Tgtimg is a utility to create and manage the image files used by the TGTD device emulation\.
 .PP
-This command is used to initialize tape image files with the additional metadata, such as barcode, list of blocks, total size, etc that the tape emulation of TGTD needs\.
-.PP
-You must use this command to initialize a file so that TGTD will\e recognize it as a tape image\.
+This command is used to initialize device image files with the additional metadata, such as barcode, list of blocks, total size, etc that the TGTD emulation needs\.
 .SH "OPTIONS"
 .PP
 \fB\-h, \-\-help\fR
@@ -40,7 +36,36 @@ Operation\. Is either new to create a new image file or show to show the content
 .PP
 \fB\-Y, \-\-device\-type <type>\fR
 .RS 4
-This specifies the type of image file\. The only valid type is tape\.
+This specifies the type of image file\.
+.RE
+.sp
+.RS 4
+.nf
+Supported device types are :
+    tape : to create media for a tape device
+    cd   : to create media for a dvd device
+      
+.fi
+.RE
+.PP
+\fB\-t, \-\-type <media\-type>\fR
+.RS 4
+When creating a new image, this specifies the type of media to emulate, normal data, cleaning image, or worm\.
+.sp
+Data is a normal tape to read/write to and probably what you want to use\.
+.RE
+.sp
+.RS 4
+.nf
+Supported media types for tape devices are :
+    data  : create a normal data tape
+    clean : create a cleaning tape
+    worm  : create a worm
+
+Supported media types for cd devices are :
+    dvd+r : create a blank writeable DVD+R disk
+      
+.fi
 .RE
 .PP
 \fB\-b, \-\-barcode <barcode>\fR
@@ -53,25 +78,18 @@ When creating a new image, this argument specifies the barcode to use with this
 When creating a new image, this specifies the size in megabytes for the virtual tape image\.
 .RE
 .PP
-\fB\-t, \-\-type {data|clean|worm}\fR
-.RS 4
-When creating a new image, this specifies the type of media to emulate, normal data, cleaning image, or worm\.
-.sp
-Data is a normal tape to read/write to and probably what you want to use\.
-.RE
-.PP
 \fB\-f, \-\-file <path>\fR
 .RS 4
 The filename of the image file\.
 .RE
 .SH "EXAMPLES"
 .PP
-To create a new image
+To create a new tape image
 .sp
 .RS 4
 .nf
-	tgtimg \-\-op new \-\-device\-type tape \-\-barcode 12345 \-\-size 100 \-\-type data \-\-file /data/tape001\.img
-      
+      tgtimg \-\-op new \-\-device\-type tape \-\-barcode 12345 \-\-size 100 \-\-type data \-\-file /data/tape001\.img
+    
 .fi
 .RE
 .PP
@@ -79,11 +97,19 @@ To view the content of an existing image
 .sp
 .RS 4
 .nf
-	tgtimg \-\-op show \-\-device\-type tape \-\-file /data/tape001\.img
-      
+      tgtimg \-\-op show \-\-device\-type tape \-\-file /data/tape001\.img
+    
 .fi
 .RE
+.PP
+To create a new blank DVD+R image
 .sp
+.RS 4
+.nf
+      tgtimg \-\-op new \-\-device\-type cd \-\-type dvd+r \-\-file /data/dvd001\.iso
+    
+.fi
+.RE
 .SH "SEE ALSO"
 .PP
 tgtd(8), tgtadm(8), tgt\-admin(8), tgt\-setup\-lun(8)\.
diff --git a/doc/tgtimg.8.xml b/doc/tgtimg.8.xml
index f12b145..a17e923 100644
--- a/doc/tgtimg.8.xml
+++ b/doc/tgtimg.8.xml
@@ -14,11 +14,13 @@
 
 <refsynopsisdiv>
 	<cmdsynopsis>
-		<command>tgtimg --op new --device-type tape </command>
-		<command>--barcode &lt;code&gt; --size &lt;size&gt; --type &lt;type&gt; --file &lt;path&gt;</command>
-	</cmdsynopsis>
-	<cmdsynopsis>
-		<command>tgtimg --op show --device-type tape --file=&lt;path&gt;</command>
+		<command>tgtimg</command>
+		<arg chouce="opt">-o --op &lt;operation&gt;</arg>
+		<arg choice="opt">-Y --device-type &lt;device-type&gt;</arg>
+		<arg choice="opt">-b --barcode &lt;barcode&gt;</arg>
+		<arg choice="opt">-s --size &lt;size&gt;</arg>
+		<arg choice="opt">-t --type &lt;media-type&gt;</arg>
+		<arg choice="opt">-f --file &lt;path&gt;</arg>
 	</cmdsynopsis>
 	<cmdsynopsis>
 		<command>tgtimg --help</command>
@@ -28,17 +30,13 @@
 
   <refsect1><title>DESCRIPTION</title>
     <para>
-      tgtimg is a utility to create and manage the image files used by the 
-      stgt tape emulation.
+      Tgtimg is a utility to create and manage the image files used by the 
+      TGTD device emulation.
     </para>
     <para>
-      This command is used to initialize tape image files with the additional
+      This command is used to initialize device image files with the additional
       metadata, such as barcode, list of blocks, total size, etc that
-      the tape emulation of TGTD needs.
-    </para>
-    <para>
-      You must use this command to initialize a file so that TGTD will\
-      recognize it as a tape image.
+      the TGTD emulation needs.
     </para>
   </refsect1>
 
@@ -67,10 +65,37 @@
       <varlistentry><term><option>-Y, --device-type &lt;type&gt;</option></term>
         <listitem>
           <para>
-	    This specifies the type of image file. The only valid type is tape.
+	    This specifies the type of image file.
           </para>
         </listitem>
       </varlistentry>
+      <screen format="linespecific">
+Supported device types are :
+    tape : to create media for a tape device
+    cd   : to create media for a dvd device
+      </screen>
+
+      <varlistentry><term><option>-t, --type &lt;media-type&gt;</option></term>
+        <listitem>
+          <para>
+	    When creating a new image, this specifies the type of media to
+	    emulate, normal data, cleaning image, or worm.
+          </para>
+          <para>
+	    Data is a normal tape to read/write to and probably what you 
+	    want to use.
+          </para>
+        </listitem>
+      </varlistentry>
+      <screen format="linespecific">
+Supported media types for tape devices are :
+    data  : create a normal data tape
+    clean : create a cleaning tape
+    worm  : create a worm
+
+Supported media types for cd devices are :
+    dvd+r : create a blank writeable DVD+R disk
+      </screen>
 
       <varlistentry><term><option>-b, --barcode &lt;barcode&gt;</option></term>
         <listitem>
@@ -92,19 +117,6 @@
         </listitem>
       </varlistentry>
 
-      <varlistentry><term><option>-t, --type {data|clean|worm}</option></term>
-        <listitem>
-          <para>
-	    When creating a new image, this specifies the type of media to
-	    emulate, normal data, cleaning image, or worm.
-          </para>
-          <para>
-	    Data is a normal tape to read/write to and probably what you 
-	    want to use.
-          </para>
-        </listitem>
-      </varlistentry>
-
       <varlistentry><term><option>-f, --file &lt;path&gt;</option></term>
         <listitem>
           <para>
@@ -118,18 +130,26 @@
 
   <refsect1><title>EXAMPLES</title>
     <para>
-      To create a new image
-      <screen format="linespecific">
-	tgtimg --op new --device-type tape --barcode 12345 --size 100 --type data --file /data/tape001.img
-      </screen>
+      To create a new tape image
     </para>
+    <screen format="linespecific">
+      tgtimg --op new --device-type tape --barcode 12345 --size 100 --type data --file /data/tape001.img
+    </screen>
 
     <para>
       To view the content of an existing image
-      <screen format="linespecific">
-	tgtimg --op show --device-type tape --file /data/tape001.img
-      </screen>
     </para>
+    <screen format="linespecific">
+      tgtimg --op show --device-type tape --file /data/tape001.img
+    </screen>
+
+    <para>
+      To create a new blank DVD+R image
+    </para>
+    <screen format="linespecific">
+      tgtimg --op new --device-type cd --type dvd+r --file /data/dvd001.iso
+    </screen>
+
   </refsect1>
 
 
diff --git a/usr/tgtimg.c b/usr/tgtimg.c
index 13f236c..c67c7f2 100644
--- a/usr/tgtimg.c
+++ b/usr/tgtimg.c
@@ -82,15 +82,17 @@ static void usage(int status)
 Linux SCSI Target Framework Image File Utility, version %s\n\
 \n\
   --op new --device-type tape --barcode=[code] --size=[size] --type=[type] --file=[path]\n\
-                         create a new tape image file.\n\
-                         [code] is a string of chars.\n\
-                         [size] is media size (in megabytes).\n\
-                         [type] is media type (data, clean or WORM)\n\
-                         [path] is a newly created file\n\
+			create a new tape image file.\n\
+			[code] is a string of chars.\n\
+			[size] is media size(in megabytes).\n\
+			[type] is media type \n\
+				(data, clean or WORM) for tape devices\n\
+				(dvd+r) for cd devices\n\
+			[path] is a newly created file\n\
   --op show --device-type tape --file=[path]\n\
-                         dump the tape image file contents.\n\
-                         [path] is the tape image file\n\
-  --help                 display this help and exit\n\
+			dump the tape image file contents.\n\
+			[path] is the tape image file\n\
+  --help                display this help and exit\n\
 \n\
 Report bugs to <stgt@xxxxxxxxxxxxxxx>.\n", TGT_VERSION);
 	}
@@ -101,6 +103,8 @@ static int str_to_device_type(char *str)
 {
 	if (!strcmp(str, "tape"))
 		return TYPE_TAPE;
+	else if (!strcmp(str, "cd"))
+		return TYPE_MMC;
 	else {
 		eprintf("unknown target type: %s\n", str);
 		exit(EINVAL);
@@ -303,7 +307,7 @@ static int ssc_new(int op, char *path, char *barcode, char *capacity,
 	sprintf((char *)mi.barcode, "%-31s", barcode);
 	sprintf((char *)current_media, "%s", barcode);
 
-	syslog(LOG_DAEMON|LOG_INFO, "%s being created", path);
+	syslog(LOG_DAEMON|LOG_INFO, "TAPE %s being created", path);
 
 	fd = creat(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
 	if (fd < 0) {
@@ -348,6 +352,13 @@ static int ssc_ops(int op, char *path, char *barcode, char *capacity,
 			eprintf("Missing media type: WORM, CLEAN or DATA\n");
 			usage(1);
 		}
+		if (strncasecmp("data", media_type, 4)
+		&& strncasecmp("clean", media_type, 5)
+		&& strncasecmp("worm", media_type, 4)) {
+			eprintf("Media type must be WORM, CLEAN or DATA"
+				       " for tape devices\n");
+			usage(1);
+		}
 		if (!barcode) {
 			eprintf("Missing the barcode param\n");
 			usage(1);
@@ -367,6 +378,49 @@ static int ssc_ops(int op, char *path, char *barcode, char *capacity,
 	return 0;
 }
 
+static int mmc_new(int op, char *path, char *media_type)
+{
+	int fd;
+
+	if (!strncasecmp("dvd+r", media_type, 5)) {
+		fd = creat(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+		if (fd < 0) {
+			perror("Failed creating file");
+			exit(2);
+		}
+		close(fd);
+
+		printf("Created blank DVD+R image file : %s\n", path);
+		syslog(LOG_DAEMON|LOG_INFO, "DVD+R %s being created", path);
+	} else {
+		eprintf("unknown media type when creating cd\n");
+		usage(1);
+	}
+
+	return 0;
+}
+
+
+static int mmc_ops(int op, char *path, char *media_type)
+{
+	if (op == OP_NEW) {
+		if (!media_type) {
+			eprintf("Missing media type: DVD+R\n");
+			usage(1);
+		}
+		if (strncasecmp("dvd+r", media_type, 5)) {
+			eprintf("Media type must be DVD+R for cd devices\n");
+			usage(1);
+		}
+		return mmc_new(op, path, media_type);
+	} else {
+		eprintf("unknown the operation type\n");
+		usage(1);
+	}
+
+	return 0;
+}
+
 int main(int argc, char **argv)
 {
 	int ch, longindex;
@@ -422,9 +476,14 @@ int main(int argc, char **argv)
 		usage(1);
 	}
 
-	if (dev_type == TYPE_TAPE)
+	switch (dev_type) {
+	case TYPE_TAPE:
 		ssc_ops(op, path, barcode, media_capacity, media_type);
-	else {
+		break;
+	case TYPE_MMC:
+		mmc_ops(op, path, media_type);
+		break;
+	default:
 		eprintf("unsupported the device type operation\n");
 		usage(1);
 	}
-- 
1.5.4.3


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux