Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > bb4034fe5c01663c50ccf1eb5169c1a5 > files > 36

libburn-devel-1.2.2-1.fc15.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>libburn: libburner.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.4 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">libburn&#160;<span id="projectnumber">1.2.2</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">libburner.c</div>  </div>
</div>
<div class="contents">
<a href="libburner_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="comment">/* test/libburner.c , API illustration of burning data or audio tracks to CD */</span>
<a name="l00003"></a>00003 <span class="comment">/* Copyright (C) 2005 - 2011 Thomas Schmitt &lt;scdbackup@gmx.net&gt; */</span>
<a name="l00004"></a>00004 <span class="comment">/* Provided under GPL, see also &quot;License and copyright aspects&quot; at file end */</span>
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment">/**                               Overview </span>
<a name="l00008"></a>00008 <span class="comment">  </span>
<a name="l00009"></a>00009 <span class="comment">  libburner is a minimal demo application for the library libburn as provided</span>
<a name="l00010"></a>00010 <span class="comment">  on  http://libburnia-project.org . It can list the available devices, can</span>
<a name="l00011"></a>00011 <span class="comment">  blank a CD-RW or DVD-RW, can format DVD-RW and BD, can burn to CD-R,</span>
<a name="l00012"></a>00012 <span class="comment">  CD-RW, DVD-R, DVD+R, DVD+R/DL, DVD+RW, DVD-RW, DVD-RAM, BD-R, BD-RE. </span>
<a name="l00013"></a>00013 <span class="comment">  Not supported yet: DVD-R/DL.</span>
<a name="l00014"></a>00014 <span class="comment"></span>
<a name="l00015"></a>00015 <span class="comment">  It&#39;s main purpose, nevertheless, is to show you how to use libburn and also</span>
<a name="l00016"></a>00016 <span class="comment">  to serve the libburnia team as reference application. libburner.c does indeed</span>
<a name="l00017"></a>00017 <span class="comment">  define the standard way how above three gestures can be implemented and</span>
<a name="l00018"></a>00018 <span class="comment">  stay upward compatible for a good while.</span>
<a name="l00019"></a>00019 <span class="comment">  </span>
<a name="l00020"></a>00020 <span class="comment">  Before you can do anything, you have to initialize libburn by</span>
<a name="l00021"></a>00021 <span class="comment">     burn_initialize()</span>
<a name="l00022"></a>00022 <span class="comment">  and provide some signal and abort handling, e.g. by the builtin handler, by</span>
<a name="l00023"></a>00023 <span class="comment">     burn_set_signal_handling(&quot;libburner : &quot;, NULL, 0x0) </span>
<a name="l00024"></a>00024 <span class="comment">  as it is done in main() at the end of this file.</span>
<a name="l00025"></a>00025 <span class="comment">  Then you aquire a drive in an appropriate way conforming to the API. The twoi</span>
<a name="l00026"></a>00026 <span class="comment">  main approaches are shown here in application functions:</span>
<a name="l00027"></a>00027 <span class="comment">     libburner_aquire_by_adr()     demonstrates usage as of cdrecord traditions</span>
<a name="l00028"></a>00028 <span class="comment">     libburner_aquire_by_driveno()      demonstrates a scan-and-choose approach</span>
<a name="l00029"></a>00029 <span class="comment"></span>
<a name="l00030"></a>00030 <span class="comment">  With that aquired drive you can blank a CD-RW or DVD-RW as shown in</span>
<a name="l00031"></a>00031 <span class="comment">     libburner_blank_disc()</span>
<a name="l00032"></a>00032 <span class="comment">  or you can format a DVD-RW to profile &quot;Restricted Overwrite&quot; (needed once)</span>
<a name="l00033"></a>00033 <span class="comment">  or an unused BD to default size with spare blocks</span>
<a name="l00034"></a>00034 <span class="comment">     libburner_format()</span>
<a name="l00035"></a>00035 <span class="comment">  With the aquired drive you can burn to CD, DVD, BD. See</span>
<a name="l00036"></a>00036 <span class="comment">     libburner_payload()</span>
<a name="l00037"></a>00037 <span class="comment"></span>
<a name="l00038"></a>00038 <span class="comment">  These three functions switch temporarily to a non-fatal signal handler</span>
<a name="l00039"></a>00039 <span class="comment">  while they are waiting for the drive to become idle again:</span>
<a name="l00040"></a>00040 <span class="comment">     burn_set_signal_handling(&quot;libburner : &quot;, NULL, 0x30)</span>
<a name="l00041"></a>00041 <span class="comment">  After the waiting loop ended, they check for eventual abort events by</span>
<a name="l00042"></a>00042 <span class="comment">     burn_is_aborting(0)</span>
<a name="l00043"></a>00043 <span class="comment">  The 0x30 handler will eventually execute</span>
<a name="l00044"></a>00044 <span class="comment">     burn_abort()</span>
<a name="l00045"></a>00045 <span class="comment">  but not wait for the drive to become idle and not call exit().</span>
<a name="l00046"></a>00046 <span class="comment">  This is needed because the worker threads might block as long as the signal</span>
<a name="l00047"></a>00047 <span class="comment">  handler has not returned. The 0x0 handler would wait for them to finish.</span>
<a name="l00048"></a>00048 <span class="comment">  Take this into respect when implementing own signal handlers.</span>
<a name="l00049"></a>00049 <span class="comment"></span>
<a name="l00050"></a>00050 <span class="comment">  When everything is done, main() releases the drive and shuts down libburn:</span>
<a name="l00051"></a>00051 <span class="comment">     burn_drive_release();</span>
<a name="l00052"></a>00052 <span class="comment">     burn_finish()</span>
<a name="l00053"></a>00053 <span class="comment"></span>
<a name="l00054"></a>00054 <span class="comment">  Applications must use 64 bit off_t. E.g. by defining</span>
<a name="l00055"></a>00055 <span class="comment">    #define _LARGEFILE_SOURCE</span>
<a name="l00056"></a>00056 <span class="comment">    #define _FILE_OFFSET_BITS 64</span>
<a name="l00057"></a>00057 <span class="comment">  or take special precautions to interface with the library by 64 bit integers</span>
<a name="l00058"></a>00058 <span class="comment">  where libburn/libburn.h prescribes off_t.</span>
<a name="l00059"></a>00059 <span class="comment">  This program gets fed with appropriate settings externally by libburn&#39;s</span>
<a name="l00060"></a>00060 <span class="comment">  autotools generated build system.</span>
<a name="l00061"></a>00061 <span class="comment">*/</span>
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="comment"></span>
<a name="l00064"></a>00064 <span class="comment">/** See this for the decisive API specs . libburn.h is The Original */</span>
<a name="l00065"></a>00065 <span class="comment">/*  For using the installed header file :  #include &lt;libburn/libburn.h&gt; */</span>
<a name="l00066"></a>00066 <span class="comment">/*  This program insists in the own headerfile. */</span>
<a name="l00067"></a>00067 <span class="preprocessor">#include &quot;../libburn/libburn.h&quot;</span>
<a name="l00068"></a>00068 
<a name="l00069"></a>00069 <span class="comment">/* libburn works on Linux systems with kernel 2.4 or 2.6, FreeBSD, Solaris */</span>
<a name="l00070"></a>00070 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00071"></a>00071 <span class="preprocessor">#include &lt;ctype.h&gt;</span>
<a name="l00072"></a>00072 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00073"></a>00073 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00074"></a>00074 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00075"></a>00075 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00076"></a>00076 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00077"></a>00077 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00078"></a>00078 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00079"></a>00079 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00080"></a>00080 
<a name="l00081"></a>00081 <span class="comment"></span>
<a name="l00082"></a>00082 <span class="comment">/** For simplicity i use global variables to represent the drives.</span>
<a name="l00083"></a>00083 <span class="comment">    Drives are systemwide global, so we do not give away much of good style.</span>
<a name="l00084"></a>00084 <span class="comment">*/</span>
<a name="l00085"></a>00085 <span class="comment"></span>
<a name="l00086"></a>00086 <span class="comment">/** This list will hold the drives known to libburn. This might be all CD</span>
<a name="l00087"></a>00087 <span class="comment">    drives of the system and thus might impose severe impact on the system.</span>
<a name="l00088"></a>00088 <span class="comment">*/</span>
<a name="l00089"></a><a class="code" href="libburner_8c.html#a271c6b9f59f56d3ac45a173461f3eeba">00089</a> <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structburn__drive__info.html" title="Information on a drive in the system.">burn_drive_info</a> *<a class="code" href="libburner_8c.html#a271c6b9f59f56d3ac45a173461f3eeba" title="Overview.">drive_list</a>;
<a name="l00090"></a>00090 <span class="comment"></span>
<a name="l00091"></a>00091 <span class="comment">/** If you start a long lasting operation with drive_count &gt; 1 then you are</span>
<a name="l00092"></a>00092 <span class="comment">    not friendly to the users of other drives on those systems. Beware. */</span>
<a name="l00093"></a><a class="code" href="libburner_8c.html#a2ab10011f756aef24f3168d95a5b439b">00093</a> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a2ab10011f756aef24f3168d95a5b439b" title="If you start a long lasting operation with drive_count &gt; 1 then you are not friendly to the users of ...">drive_count</a>;
<a name="l00094"></a>00094 <span class="comment"></span>
<a name="l00095"></a>00095 <span class="comment">/** This variable indicates wether the drive is grabbed and must be</span>
<a name="l00096"></a>00096 <span class="comment">    finally released */</span>
<a name="l00097"></a><a class="code" href="libburner_8c.html#aaee536e445f55d19bfeb431850ec90e4">00097</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#aaee536e445f55d19bfeb431850ec90e4" title="This variable indicates wether the drive is grabbed and must be finally released.">drive_is_grabbed</a> = 0;
<a name="l00098"></a>00098 <span class="comment"></span>
<a name="l00099"></a>00099 <span class="comment">/** A number and a text describing the type of media in aquired drive */</span>
<a name="l00100"></a><a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043">00100</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a>= -1;
<a name="l00101"></a><a class="code" href="libburner_8c.html#a14fb7b17efb56d94fb7d794053ae045b">00101</a> <span class="keyword">static</span> <span class="keywordtype">char</span> <a class="code" href="libburner_8c.html#a14fb7b17efb56d94fb7d794053ae045b">current_profile_name</a>[80]= {<span class="stringliteral">&quot;&quot;</span>};
<a name="l00102"></a>00102 
<a name="l00103"></a>00103 
<a name="l00104"></a>00104 <span class="comment">/* Some in-advance definitions to allow a more comprehensive ordering</span>
<a name="l00105"></a>00105 <span class="comment">   of the functions and their explanations in here */</span>
<a name="l00106"></a>00106 <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a3ed4822421dfb49c359b85accd952b56" title="If the persistent drive address is known, then this approach is much more un-obtrusive to the systemw...">libburner_aquire_by_adr</a>(<span class="keywordtype">char</span> *<a class="code" href="libburner_8c.html#adbe410a004b2aefa8868608beb2e5df1" title="The setup parameters of libburner.">drive_adr</a>);
<a name="l00107"></a>00107 <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#aa2de071d4fb803b4a171dbc8dc14be5c" title="This method demonstrates how to use libburn without knowing a persistent drive address in advance...">libburner_aquire_by_driveno</a>(<span class="keywordtype">int</span> *drive_no);
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 
<a name="l00110"></a>00110 <span class="comment">/* ------------------------------- API gestures ---------------------------- */</span>
<a name="l00111"></a>00111 <span class="comment"></span>
<a name="l00112"></a>00112 <span class="comment">/** You need to aquire a drive before burning. The API offers this as one</span>
<a name="l00113"></a>00113 <span class="comment">    compact call and alternatively as application controllable gestures of</span>
<a name="l00114"></a>00114 <span class="comment">    whitelisting, scanning for drives and finally grabbing one of them.</span>
<a name="l00115"></a>00115 <span class="comment"></span>
<a name="l00116"></a>00116 <span class="comment">    If you have a persistent address of the drive, then the compact call is</span>
<a name="l00117"></a>00117 <span class="comment">    to prefer because it only touches one drive. On modern Linux kernels,</span>
<a name="l00118"></a>00118 <span class="comment">    there should be no fatal disturbance of ongoing burns of other libburn</span>
<a name="l00119"></a>00119 <span class="comment">    instances with any of our approaches. We use open(O_EXCL) by default.</span>
<a name="l00120"></a>00120 <span class="comment">    On /dev/hdX it should cooperate with growisofs and some cdrecord variants.</span>
<a name="l00121"></a>00121 <span class="comment">    On /dev/sgN versus /dev/scdM expect it not to respect other programs.</span>
<a name="l00122"></a>00122 <span class="comment">*/</span>
<a name="l00123"></a><a class="code" href="libburner_8c.html#ab485e1b9ba9572fb7596ffa6d6ff67c7">00123</a> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#ab485e1b9ba9572fb7596ffa6d6ff67c7" title="You need to aquire a drive before burning.">libburner_aquire_drive</a>(<span class="keywordtype">char</span> *<a class="code" href="libburner_8c.html#adbe410a004b2aefa8868608beb2e5df1" title="The setup parameters of libburner.">drive_adr</a>, <span class="keywordtype">int</span> *<a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a>)
<a name="l00124"></a>00124 {
<a name="l00125"></a>00125     <span class="keywordtype">int</span> ret;
<a name="l00126"></a>00126 
<a name="l00127"></a>00127     <span class="keywordflow">if</span>(drive_adr != NULL &amp;&amp; drive_adr[0] != 0)
<a name="l00128"></a>00128         ret = <a class="code" href="libburner_8c.html#a3ed4822421dfb49c359b85accd952b56" title="If the persistent drive address is known, then this approach is much more un-obtrusive to the systemw...">libburner_aquire_by_adr</a>(drive_adr);
<a name="l00129"></a>00129     <span class="keywordflow">else</span>
<a name="l00130"></a>00130         ret = <a class="code" href="libburner_8c.html#aa2de071d4fb803b4a171dbc8dc14be5c" title="This method demonstrates how to use libburn without knowing a persistent drive address in advance...">libburner_aquire_by_driveno</a>(driveno);
<a name="l00131"></a>00131     <span class="keywordflow">if</span> (ret &lt;= 0 || *driveno &lt;= 0)
<a name="l00132"></a>00132         <span class="keywordflow">return</span> ret;
<a name="l00133"></a>00133     <a class="code" href="libburn_8h.html#a1627c70c71ec5b6116f8d9d63d229285" title="Tells the MMC Profile identifier of the loaded media.">burn_disc_get_profile</a>(drive_list[0].<a class="code" href="structburn__drive__info.html#aa53408d48157a07e48b114e6c95550d0" title="The value by which this drive can be indexed when using functions in the library.">drive</a>, &amp;<a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a>,
<a name="l00134"></a>00134                  <a class="code" href="libburner_8c.html#a14fb7b17efb56d94fb7d794053ae045b">current_profile_name</a>);
<a name="l00135"></a>00135     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#a14fb7b17efb56d94fb7d794053ae045b">current_profile_name</a>[0])
<a name="l00136"></a>00136         printf(<span class="stringliteral">&quot;Detected media type: %s\n&quot;</span>, <a class="code" href="libburner_8c.html#a14fb7b17efb56d94fb7d794053ae045b">current_profile_name</a>);
<a name="l00137"></a>00137     <span class="keywordflow">return</span> 1;
<a name="l00138"></a>00138 }
<a name="l00139"></a>00139 
<a name="l00140"></a>00140 <span class="comment"></span>
<a name="l00141"></a>00141 <span class="comment">/** If the persistent drive address is known, then this approach is much</span>
<a name="l00142"></a>00142 <span class="comment">    more un-obtrusive to the systemwide livestock of drives. Only the</span>
<a name="l00143"></a>00143 <span class="comment">    given drive device will be opened during this procedure.</span>
<a name="l00144"></a>00144 <span class="comment">*/</span>
<a name="l00145"></a><a class="code" href="libburner_8c.html#a3ed4822421dfb49c359b85accd952b56">00145</a> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a3ed4822421dfb49c359b85accd952b56" title="If the persistent drive address is known, then this approach is much more un-obtrusive to the systemw...">libburner_aquire_by_adr</a>(<span class="keywordtype">char</span> *<a class="code" href="libburner_8c.html#adbe410a004b2aefa8868608beb2e5df1" title="The setup parameters of libburner.">drive_adr</a>)
<a name="l00146"></a>00146 {
<a name="l00147"></a>00147     <span class="keywordtype">int</span> ret;
<a name="l00148"></a>00148     <span class="keywordtype">char</span> libburn_drive_adr[<a class="code" href="libburn_8h.html#a489ca2111726a034324275aca4ed069c" title="Maximum length+1 to expect with a drive device file address string.">BURN_DRIVE_ADR_LEN</a>];
<a name="l00149"></a>00149 
<a name="l00150"></a>00150     <span class="comment">/* Some not-so-harmless drive addresses get blocked in this demo */</span>
<a name="l00151"></a>00151     <span class="keywordflow">if</span> (strncmp(drive_adr, <span class="stringliteral">&quot;stdio:/dev/fd/&quot;</span>, 14) == 0 ||
<a name="l00152"></a>00152         strcmp(drive_adr, <span class="stringliteral">&quot;stdio:-&quot;</span>) == 0) {
<a name="l00153"></a>00153         fprintf(stderr, <span class="stringliteral">&quot;Will not work with pseudo-drive &#39;%s&#39;\n&quot;</span>,
<a name="l00154"></a>00154             drive_adr);
<a name="l00155"></a>00155         <span class="keywordflow">return</span> 0;
<a name="l00156"></a>00156     }
<a name="l00157"></a>00157 
<a name="l00158"></a>00158     <span class="comment">/* This tries to resolve links or alternative device files */</span>
<a name="l00159"></a>00159     ret = <a class="code" href="libburn_8h.html#a1b0e38d691eeb1da5f34a6ef0cc052bc" title="Try to convert a given existing filesystem address into a drive device file address.">burn_drive_convert_fs_adr</a>(drive_adr, libburn_drive_adr);  
<a name="l00160"></a>00160     <span class="keywordflow">if</span> (ret&lt;=0) {
<a name="l00161"></a>00161         fprintf(stderr, <span class="stringliteral">&quot;Address does not lead to a CD burner: &#39;%s&#39;\n&quot;</span>,
<a name="l00162"></a>00162                  drive_adr);
<a name="l00163"></a>00163         <span class="keywordflow">return</span> 0;
<a name="l00164"></a>00164     }
<a name="l00165"></a>00165     fprintf(stderr,<span class="stringliteral">&quot;Aquiring drive &#39;%s&#39; ...\n&quot;</span>, libburn_drive_adr);
<a name="l00166"></a>00166     ret = <a class="code" href="libburn_8h.html#ae9c75e892e445ff73c38579210ba06a9" title="Aquire a drive with known device file address.">burn_drive_scan_and_grab</a>(&amp;drive_list, libburn_drive_adr, 1);
<a name="l00167"></a>00167     <span class="keywordflow">if</span> (ret &lt;= 0) {
<a name="l00168"></a>00168         fprintf(stderr,<span class="stringliteral">&quot;FAILURE with persistent drive address  &#39;%s&#39;\n&quot;</span>,
<a name="l00169"></a>00169             libburn_drive_adr);
<a name="l00170"></a>00170     } <span class="keywordflow">else</span> {
<a name="l00171"></a>00171         fprintf(stderr,<span class="stringliteral">&quot;Done\n&quot;</span>);
<a name="l00172"></a>00172         <a class="code" href="libburner_8c.html#aaee536e445f55d19bfeb431850ec90e4" title="This variable indicates wether the drive is grabbed and must be finally released.">drive_is_grabbed</a> = 1;
<a name="l00173"></a>00173     }
<a name="l00174"></a>00174     <span class="keywordflow">return</span> ret;
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 
<a name="l00177"></a>00177 <span class="comment"></span>
<a name="l00178"></a>00178 <span class="comment">/** This method demonstrates how to use libburn without knowing a persistent</span>
<a name="l00179"></a>00179 <span class="comment">    drive address in advance. It has to make sure that after assessing the list</span>
<a name="l00180"></a>00180 <span class="comment">    of available drives, all unwanted drives get closed again. As long as they</span>
<a name="l00181"></a>00181 <span class="comment">    are open, no other libburn instance can see them. This is an intended</span>
<a name="l00182"></a>00182 <span class="comment">    locking feature. The application is responsible for giving up the locks</span>
<a name="l00183"></a>00183 <span class="comment">    by either burn_drive_release() (only after burn_drive_grab() !),</span>
<a name="l00184"></a>00184 <span class="comment">    burn_drive_info_forget(), burn_drive_info_free(), or burn_finish().</span>
<a name="l00185"></a>00185 <span class="comment">    @param driveno the index number in libburn&#39;s drive list. This will get</span>
<a name="l00186"></a>00186 <span class="comment">                   set to 0 on success and will then be the drive index to</span>
<a name="l00187"></a>00187 <span class="comment">                   use in the further dourse of processing.</span>
<a name="l00188"></a>00188 <span class="comment">    @return 1 success , &lt;= 0 failure</span>
<a name="l00189"></a>00189 <span class="comment">*/</span>
<a name="l00190"></a><a class="code" href="libburner_8c.html#aa2de071d4fb803b4a171dbc8dc14be5c">00190</a> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#aa2de071d4fb803b4a171dbc8dc14be5c" title="This method demonstrates how to use libburn without knowing a persistent drive address in advance...">libburner_aquire_by_driveno</a>(<span class="keywordtype">int</span> *<a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a>)
<a name="l00191"></a>00191 {
<a name="l00192"></a>00192     <span class="keywordtype">char</span> adr[<a class="code" href="libburn_8h.html#a489ca2111726a034324275aca4ed069c" title="Maximum length+1 to expect with a drive device file address string.">BURN_DRIVE_ADR_LEN</a>];
<a name="l00193"></a>00193     <span class="keywordtype">int</span> ret, i;
<a name="l00194"></a>00194 
<a name="l00195"></a>00195     printf(<span class="stringliteral">&quot;Beginning to scan for devices ...\n&quot;</span>);
<a name="l00196"></a>00196     <span class="keywordflow">while</span> (!<a class="code" href="libburn_8h.html#a21b480156713f0dbc8a254c24fa9689e" title="Scan for drives.">burn_drive_scan</a>(&amp;drive_list, &amp;<a class="code" href="libburner_8c.html#a2ab10011f756aef24f3168d95a5b439b" title="If you start a long lasting operation with drive_count &gt; 1 then you are not friendly to the users of ...">drive_count</a>))
<a name="l00197"></a>00197         usleep(100002);
<a name="l00198"></a>00198     <span class="keywordflow">if</span> (drive_count &lt;= 0 &amp;&amp; *driveno &gt;= 0) {
<a name="l00199"></a>00199         printf(<span class="stringliteral">&quot;FAILED (no drives found)\n&quot;</span>);
<a name="l00200"></a>00200         <span class="keywordflow">return</span> 0;
<a name="l00201"></a>00201     }
<a name="l00202"></a>00202     printf(<span class="stringliteral">&quot;Done\n&quot;</span>);
<a name="l00203"></a>00203 
<a name="l00204"></a>00204     <span class="comment">/*</span>
<a name="l00205"></a>00205 <span class="comment">    Interactive programs may choose the drive number at this moment.</span>
<a name="l00206"></a>00206 <span class="comment"></span>
<a name="l00207"></a>00207 <span class="comment">    drive[0] to drive[drive_count-1] are struct burn_drive_info</span>
<a name="l00208"></a>00208 <span class="comment">    as defined in  libburn/libburn.h  . This structure is part of API</span>
<a name="l00209"></a>00209 <span class="comment">    and thus will strive for future compatibility on source level.</span>
<a name="l00210"></a>00210 <span class="comment">    Have a look at the info offered.</span>
<a name="l00211"></a>00211 <span class="comment">    Caution: do not take .location for drive address. Always use</span>
<a name="l00212"></a>00212 <span class="comment">        burn_drive_get_adr() or you might become incompatible</span>
<a name="l00213"></a>00213 <span class="comment">        in future.</span>
<a name="l00214"></a>00214 <span class="comment">    Note: bugs with struct burn_drive_info - if any - will not be</span>
<a name="l00215"></a>00215 <span class="comment">        easy to fix. Please report them but also strive for</span>
<a name="l00216"></a>00216 <span class="comment">        workarounds on application level.</span>
<a name="l00217"></a>00217 <span class="comment">    */</span>
<a name="l00218"></a>00218     printf(<span class="stringliteral">&quot;\nOverview of accessible drives (%d found) :\n&quot;</span>,
<a name="l00219"></a>00219         <a class="code" href="libburner_8c.html#a2ab10011f756aef24f3168d95a5b439b" title="If you start a long lasting operation with drive_count &gt; 1 then you are not friendly to the users of ...">drive_count</a>);
<a name="l00220"></a>00220     printf(<span class="stringliteral">&quot;-----------------------------------------------------------------------------\n&quot;</span>);
<a name="l00221"></a>00221     <span class="keywordflow">for</span> (i = 0; i &lt; (int) <a class="code" href="libburner_8c.html#a2ab10011f756aef24f3168d95a5b439b" title="If you start a long lasting operation with drive_count &gt; 1 then you are not friendly to the users of ...">drive_count</a>; i++) {
<a name="l00222"></a>00222         <span class="keywordflow">if</span> (<a class="code" href="libburn_8h.html#a1ccfaccc7c7b10aa7f25bec20cf1b1b2" title="Inquire the device file address of a drive via a given drive_info object.">burn_drive_get_adr</a>(&amp;(drive_list[i]), adr) &lt;=0)
<a name="l00223"></a>00223             strcpy(adr, <span class="stringliteral">&quot;-get_adr_failed-&quot;</span>);
<a name="l00224"></a>00224         printf(<span class="stringliteral">&quot;%d  --drive &#39;%s&#39;  :  &#39;%s&#39;  &#39;%s&#39;\n&quot;</span>,
<a name="l00225"></a>00225             i,adr,drive_list[i].<a class="code" href="structburn__drive__info.html#aff3ff7a51541d619f7f156ba58256992" title="Name of the vendor of the drive.">vendor</a>,drive_list[i].<a class="code" href="structburn__drive__info.html#a679639bfb29abb68d5b35269e935e88f" title="Name of the drive.">product</a>);
<a name="l00226"></a>00226     }
<a name="l00227"></a>00227     printf(<span class="stringliteral">&quot;-----------------------------------------------------------------------------\n\n&quot;</span>);
<a name="l00228"></a>00228 
<a name="l00229"></a>00229     <span class="comment">/*</span>
<a name="l00230"></a>00230 <span class="comment">    On multi-drive systems save yourself from sysadmins&#39; revenge.</span>
<a name="l00231"></a>00231 <span class="comment"></span>
<a name="l00232"></a>00232 <span class="comment">    Be aware that you hold reserved all available drives at this point.</span>
<a name="l00233"></a>00233 <span class="comment">    So either make your choice quick enough not to annoy other system</span>
<a name="l00234"></a>00234 <span class="comment">    users, or set free the drives for a while.</span>
<a name="l00235"></a>00235 <span class="comment"></span>
<a name="l00236"></a>00236 <span class="comment">    The tested way of setting free all drives is to shutdown the library</span>
<a name="l00237"></a>00237 <span class="comment">    and to restart when the choice has been made. The list of selectable</span>
<a name="l00238"></a>00238 <span class="comment">    drives should also hold persistent drive addresses as obtained</span>
<a name="l00239"></a>00239 <span class="comment">    above by burn_drive_get_adr(). By such an address one may use</span>
<a name="l00240"></a>00240 <span class="comment">    burn_drive_scan_and_grab() to finally aquire exactly one drive.</span>
<a name="l00241"></a>00241 <span class="comment"></span>
<a name="l00242"></a>00242 <span class="comment">    A not yet tested shortcut should be to call burn_drive_info_free()</span>
<a name="l00243"></a>00243 <span class="comment">    and to call either burn_drive_scan() or burn_drive_scan_and_grab()</span>
<a name="l00244"></a>00244 <span class="comment">    before accessing any drives again.</span>
<a name="l00245"></a>00245 <span class="comment"></span>
<a name="l00246"></a>00246 <span class="comment">    In both cases you have to be aware that the desired drive might get</span>
<a name="l00247"></a>00247 <span class="comment">    aquired in the meantime by another user resp. libburn process.</span>
<a name="l00248"></a>00248 <span class="comment">    */</span>
<a name="l00249"></a>00249 
<a name="l00250"></a>00250     <span class="comment">/* We already made our choice via command line. (default is 0)</span>
<a name="l00251"></a>00251 <span class="comment">       So we just have to keep our desired drive and drop all others.</span>
<a name="l00252"></a>00252 <span class="comment">       No other libburn instance will have a chance to steal our drive.</span>
<a name="l00253"></a>00253 <span class="comment">     */</span>
<a name="l00254"></a>00254     <span class="keywordflow">if</span> (*driveno &lt; 0) {
<a name="l00255"></a>00255         printf(<span class="stringliteral">&quot;Pseudo-drive \&quot;-\&quot; given : bus scanning done.\n&quot;</span>);
<a name="l00256"></a>00256         <span class="keywordflow">return</span> 2; <span class="comment">/* the program will end after this */</span>
<a name="l00257"></a>00257     }
<a name="l00258"></a>00258     <span class="keywordflow">if</span> ((<span class="keywordtype">int</span>) <a class="code" href="libburner_8c.html#a2ab10011f756aef24f3168d95a5b439b" title="If you start a long lasting operation with drive_count &gt; 1 then you are not friendly to the users of ...">drive_count</a> &lt;= *driveno) {
<a name="l00259"></a>00259         fprintf(stderr,
<a name="l00260"></a>00260             <span class="stringliteral">&quot;Found only %d drives. Number %d not available.\n&quot;</span>,
<a name="l00261"></a>00261             <a class="code" href="libburner_8c.html#a2ab10011f756aef24f3168d95a5b439b" title="If you start a long lasting operation with drive_count &gt; 1 then you are not friendly to the users of ...">drive_count</a>, *driveno);
<a name="l00262"></a>00262         <span class="keywordflow">return</span> 0; <span class="comment">/* the program will end after this */</span>
<a name="l00263"></a>00263     }
<a name="l00264"></a>00264 
<a name="l00265"></a>00265     <span class="comment">/* Drop all drives which we do not want to use */</span>
<a name="l00266"></a>00266     <span class="keywordflow">for</span> (i = 0; i &lt; (int) <a class="code" href="libburner_8c.html#a2ab10011f756aef24f3168d95a5b439b" title="If you start a long lasting operation with drive_count &gt; 1 then you are not friendly to the users of ...">drive_count</a>; i++) {
<a name="l00267"></a>00267         <span class="keywordflow">if</span> (i == *driveno) <span class="comment">/* the one drive we want to keep */</span>
<a name="l00268"></a>00268     <span class="keywordflow">continue</span>;
<a name="l00269"></a>00269         ret = <a class="code" href="libburn_8h.html#a9ac4cfc83330f237b6b3824e58039775" title="Release memory about a single drive and any exclusive lock on it.">burn_drive_info_forget</a>(&amp;(drive_list[i]),0);
<a name="l00270"></a>00270         <span class="keywordflow">if</span> (ret != 1)
<a name="l00271"></a>00271             fprintf(stderr, <span class="stringliteral">&quot;Cannot drop drive %d. Please report \&quot;ret=%d\&quot; to libburn-hackers@pykix.org\n&quot;</span>,
<a name="l00272"></a>00272                 i, ret);
<a name="l00273"></a>00273         <span class="keywordflow">else</span>
<a name="l00274"></a>00274             printf(<span class="stringliteral">&quot;Dropped unwanted drive %d\n&quot;</span>,i);
<a name="l00275"></a>00275     }
<a name="l00276"></a>00276     <span class="comment">/* Make the one we want ready for blanking or burning */</span>
<a name="l00277"></a>00277     ret= <a class="code" href="libburn_8h.html#a392a1a309e906c35b8e2f31cc3f30969" title="Grab a drive.">burn_drive_grab</a>(drive_list[*driveno].<a class="code" href="structburn__drive__info.html#aa53408d48157a07e48b114e6c95550d0" title="The value by which this drive can be indexed when using functions in the library.">drive</a>, 1);
<a name="l00278"></a>00278     <span class="keywordflow">if</span> (ret != 1)
<a name="l00279"></a>00279         <span class="keywordflow">return</span> 0;
<a name="l00280"></a>00280     <a class="code" href="libburner_8c.html#aaee536e445f55d19bfeb431850ec90e4" title="This variable indicates wether the drive is grabbed and must be finally released.">drive_is_grabbed</a> = 1;
<a name="l00281"></a>00281     <span class="keywordflow">return</span> 1;
<a name="l00282"></a>00282 }
<a name="l00283"></a>00283 
<a name="l00284"></a>00284 <span class="comment"></span>
<a name="l00285"></a>00285 <span class="comment">/** Makes a previously used CD-RW or unformatted DVD-RW ready for thorough</span>
<a name="l00286"></a>00286 <span class="comment">    re-usal.</span>
<a name="l00287"></a>00287 <span class="comment"></span>
<a name="l00288"></a>00288 <span class="comment">    To our knowledge it is hardly possible to abort an ongoing blank operation</span>
<a name="l00289"></a>00289 <span class="comment">    because after start it is entirely handled by the drive.</span>
<a name="l00290"></a>00290 <span class="comment">    So expect signal handling to wait the normal blanking timespan until it</span>
<a name="l00291"></a>00291 <span class="comment">    can allow the process to end. External kill -9 will not help the drive.</span>
<a name="l00292"></a>00292 <span class="comment">*/</span>
<a name="l00293"></a><a class="code" href="libburner_8c.html#a0d4b7dff006b3f1f2aac1acc48ba99df">00293</a> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a0d4b7dff006b3f1f2aac1acc48ba99df" title="Makes a previously used CD-RW or unformatted DVD-RW ready for thorough re-usal.">libburner_blank_disc</a>(<span class="keyword">struct</span> burn_drive *<a class="code" href="structburn__drive__info.html#aa53408d48157a07e48b114e6c95550d0" title="The value by which this drive can be indexed when using functions in the library.">drive</a>, <span class="keywordtype">int</span> blank_fast)
<a name="l00294"></a>00294 {
<a name="l00295"></a>00295     <span class="keyword">enum</span> <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54" title="Possible status of the drive in regard to the disc in it.">burn_disc_status</a> disc_state;
<a name="l00296"></a>00296     <span class="keyword">struct </span><a class="code" href="structburn__progress.html" title="Operation progress report.">burn_progress</a> p;
<a name="l00297"></a>00297     <span class="keywordtype">double</span> percent = 1.0;
<a name="l00298"></a>00298 
<a name="l00299"></a>00299     disc_state = <a class="code" href="libburn_8h.html#ac009cc9dfe07c8c0b67f528a369fd511" title="Returns what kind of disc a drive is holding.">burn_disc_get_status</a>(drive);
<a name="l00300"></a>00300     printf(
<a name="l00301"></a>00301         <span class="stringliteral">&quot;Drive media status:  %d  (see  libburn/libburn.h  BURN_DISC_*)\n&quot;</span>,
<a name="l00302"></a>00302         disc_state);
<a name="l00303"></a>00303     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> == 0x13) {
<a name="l00304"></a>00304         ; <span class="comment">/* formatted DVD-RW will get blanked to sequential state */</span>
<a name="l00305"></a>00305     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (disc_state == <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54a59c757934ef338281512efce4ab6fd93" title="The drive holds a blank disc.">BURN_DISC_BLANK</a>) {
<a name="l00306"></a>00306         fprintf(stderr,
<a name="l00307"></a>00307           <span class="stringliteral">&quot;IDLE: Blank media detected. Will leave it untouched\n&quot;</span>);
<a name="l00308"></a>00308         <span class="keywordflow">return</span> 2;
<a name="l00309"></a>00309     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (disc_state == <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54ae0ea0a584e319ee775062c88975c93cd" title="There is a disc with data on it in the drive.">BURN_DISC_FULL</a> ||
<a name="l00310"></a>00310            disc_state == <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54acda6fac8462fa9affb4bff80daa2ab3f" title="There is an incomplete disc in the drive.">BURN_DISC_APPENDABLE</a>) {
<a name="l00311"></a>00311         ; <span class="comment">/* this is what libburner is willing to blank */</span>
<a name="l00312"></a>00312     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (disc_state == <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54a23eef5011f3aa95ce1858a2930c22c69" title="There is no disc at all in the drive.">BURN_DISC_EMPTY</a>) {
<a name="l00313"></a>00313         fprintf(stderr,<span class="stringliteral">&quot;FATAL: No media detected in drive\n&quot;</span>);
<a name="l00314"></a>00314         <span class="keywordflow">return</span> 0;
<a name="l00315"></a>00315     } <span class="keywordflow">else</span> {
<a name="l00316"></a>00316         fprintf(stderr,
<a name="l00317"></a>00317             <span class="stringliteral">&quot;FATAL: Unsuitable drive and media state\n&quot;</span>);
<a name="l00318"></a>00318         <span class="keywordflow">return</span> 0;
<a name="l00319"></a>00319     }
<a name="l00320"></a>00320     <span class="keywordflow">if</span>(!<a class="code" href="libburn_8h.html#a7838224062ed72305f3c6b1055cb1a98" title="Tells whether a disc can be erased or not.">burn_disc_erasable</a>(drive)) {
<a name="l00321"></a>00321         fprintf(stderr,
<a name="l00322"></a>00322             <span class="stringliteral">&quot;FATAL : Media is not of erasable type\n&quot;</span>);
<a name="l00323"></a>00323         <span class="keywordflow">return</span> 0;
<a name="l00324"></a>00324     }
<a name="l00325"></a>00325     <span class="comment">/* Switch to asynchronous signal handling for the time of waiting */</span>
<a name="l00326"></a>00326     <a class="code" href="libburn_8h.html#a47b6e05ca3f53ca00f0ef4103eb5cd18" title="Control built-in signal handling.">burn_set_signal_handling</a>(<span class="stringliteral">&quot;libburner : &quot;</span>, NULL, 0x30);
<a name="l00327"></a>00327 
<a name="l00328"></a>00328     printf(<span class="stringliteral">&quot;Beginning to %s-blank media.\n&quot;</span>, (blank_fast?<span class="stringliteral">&quot;fast&quot;</span>:<span class="stringliteral">&quot;full&quot;</span>));
<a name="l00329"></a>00329     <a class="code" href="libburn_8h.html#a86a5394e31ab522bca8cc5b7990f1923" title="Erase a disc in the drive.">burn_disc_erase</a>(drive, blank_fast);
<a name="l00330"></a>00330 
<a name="l00331"></a>00331     sleep(1);
<a name="l00332"></a>00332     <span class="keywordflow">while</span> (<a class="code" href="libburn_8h.html#a992777abdf1f13f1e2c45271e43e9a3d" title="Returns the progress and status of a drive.">burn_drive_get_status</a>(drive, &amp;p) != <a class="code" href="libburn_8h.html#a3cb9c75648e773f63911b0975f67802badcb522cf8ccf1349e3d69826c3e1757f" title="The drive is not in an operation.">BURN_DRIVE_IDLE</a>) {
<a name="l00333"></a>00333         <span class="keywordflow">if</span>(p.<a class="code" href="structburn__progress.html#af093a66f1ae097ba40eeac7e1c6ac5d9" title="On write: The number of sectors.">sectors</a>&gt;0 &amp;&amp; p.<a class="code" href="structburn__progress.html#a7aa74bd989075ae02a5066003874c60d" title="On write: The current sector being processed.">sector</a>&gt;=0) <span class="comment">/* display 1 to 99 percent */</span>
<a name="l00334"></a>00334             percent = 1.0 + ((double) p.<a class="code" href="structburn__progress.html#a7aa74bd989075ae02a5066003874c60d" title="On write: The current sector being processed.">sector</a>+1.0)
<a name="l00335"></a>00335                      / ((double) p.<a class="code" href="structburn__progress.html#af093a66f1ae097ba40eeac7e1c6ac5d9" title="On write: The number of sectors.">sectors</a>) * 98.0;
<a name="l00336"></a>00336         printf(<span class="stringliteral">&quot;Blanking  ( %.1f%% done )\n&quot;</span>, percent);
<a name="l00337"></a>00337         sleep(1);
<a name="l00338"></a>00338     }
<a name="l00339"></a>00339     <span class="keywordflow">if</span> (<a class="code" href="libburn_8h.html#a98a208e78cc9126a07d1bceea775f4db">burn_is_aborting</a>(0) &gt; 0)
<a name="l00340"></a>00340         <span class="keywordflow">return</span> -1;
<a name="l00341"></a>00341     <span class="comment">/* Back to synchronous handling */</span>
<a name="l00342"></a>00342     <a class="code" href="libburn_8h.html#a47b6e05ca3f53ca00f0ef4103eb5cd18" title="Control built-in signal handling.">burn_set_signal_handling</a>(<span class="stringliteral">&quot;libburner : &quot;</span>, NULL, 0x0);
<a name="l00343"></a>00343     printf(<span class="stringliteral">&quot;Done\n&quot;</span>);
<a name="l00344"></a>00344     <span class="keywordflow">return</span> 1;
<a name="l00345"></a>00345 }
<a name="l00346"></a>00346 
<a name="l00347"></a>00347 <span class="comment"></span>
<a name="l00348"></a>00348 <span class="comment">/** Formats unformatted DVD-RW to profile 0013h &quot;Restricted Overwrite&quot;</span>
<a name="l00349"></a>00349 <span class="comment">    which needs no blanking for re-use but is not capable of multi-session.</span>
<a name="l00350"></a>00350 <span class="comment">    Expect a behavior similar to blanking with unusual noises from the drive.</span>
<a name="l00351"></a>00351 <span class="comment"></span>
<a name="l00352"></a>00352 <span class="comment">    Formats unformatted BD-RE to default size. This will allocate some</span>
<a name="l00353"></a>00353 <span class="comment">    reserve space, test for bad blocks and make the media ready for writing.</span>
<a name="l00354"></a>00354 <span class="comment">    Expect a very long run time.</span>
<a name="l00355"></a>00355 <span class="comment"></span>
<a name="l00356"></a>00356 <span class="comment">    Formats unformatted blank BD-R to hold a default amount of spare blocks</span>
<a name="l00357"></a>00357 <span class="comment">    for eventual mishaps during writing. If BD-R get written without being</span>
<a name="l00358"></a>00358 <span class="comment">    formatted, then they get no such reserve and will burn at full speed.</span>
<a name="l00359"></a>00359 <span class="comment">*/</span>
<a name="l00360"></a><a class="code" href="libburner_8c.html#a42f03141c04bc55410fdc8e93c4f0143">00360</a> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a42f03141c04bc55410fdc8e93c4f0143" title="Formats unformatted DVD-RW to profile 0013h &quot;Restricted Overwrite&quot; which needs no blanking for re-use...">libburner_format</a>(<span class="keyword">struct</span> burn_drive *drive)
<a name="l00361"></a>00361 {
<a name="l00362"></a>00362     <span class="keyword">struct </span><a class="code" href="structburn__progress.html" title="Operation progress report.">burn_progress</a> p;
<a name="l00363"></a>00363     <span class="keywordtype">double</span> percent = 1.0;
<a name="l00364"></a>00364     <span class="keywordtype">int</span> ret, status, num_formats, format_flag= 0;
<a name="l00365"></a>00365     off_t size = 0;
<a name="l00366"></a>00366     <span class="keywordtype">unsigned</span> dummy;
<a name="l00367"></a>00367     <span class="keyword">enum</span> <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54" title="Possible status of the drive in regard to the disc in it.">burn_disc_status</a> disc_state;
<a name="l00368"></a>00368 
<a name="l00369"></a>00369     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> == 0x13) {
<a name="l00370"></a>00370         fprintf(stderr, <span class="stringliteral">&quot;IDLE: DVD-RW media is already formatted\n&quot;</span>);
<a name="l00371"></a>00371         <span class="keywordflow">return</span> 2;
<a name="l00372"></a>00372     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> == 0x41 || <a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> == 0x43) {
<a name="l00373"></a>00373         disc_state = <a class="code" href="libburn_8h.html#ac009cc9dfe07c8c0b67f528a369fd511" title="Returns what kind of disc a drive is holding.">burn_disc_get_status</a>(drive);
<a name="l00374"></a>00374         <span class="keywordflow">if</span> (disc_state != <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54a59c757934ef338281512efce4ab6fd93" title="The drive holds a blank disc.">BURN_DISC_BLANK</a> &amp;&amp; <a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> == 0x41) {
<a name="l00375"></a>00375             fprintf(stderr,
<a name="l00376"></a>00376                 <span class="stringliteral">&quot;FATAL: BD-R is not blank. Cannot format.\n&quot;</span>);
<a name="l00377"></a>00377             <span class="keywordflow">return</span> 0;
<a name="l00378"></a>00378         }
<a name="l00379"></a>00379         ret = <a class="code" href="libburn_8h.html#abe718b844984771afe7c38f44e7abbe6" title="Inquire the formatting status, the associated sizes and the number of available formats.">burn_disc_get_formats</a>(drive, &amp;status, &amp;size, &amp;dummy,
<a name="l00380"></a>00380                                 &amp;num_formats);
<a name="l00381"></a>00381         <span class="keywordflow">if</span> (ret &gt; 0 &amp;&amp; status != <a class="code" href="libburn_8h.html#a7b6978947a00d7f643003a1103b8a821" title="Possible formatting status values.">BURN_FORMAT_IS_UNFORMATTED</a>) {
<a name="l00382"></a>00382             fprintf(stderr,
<a name="l00383"></a>00383                 <span class="stringliteral">&quot;IDLE: BD media is already formatted\n&quot;</span>);
<a name="l00384"></a>00384             <span class="keywordflow">return</span> 2;
<a name="l00385"></a>00385         }
<a name="l00386"></a>00386         size = 0;           <span class="comment">/* does not really matter */</span>
<a name="l00387"></a>00387         format_flag = 3&lt;&lt;1; <span class="comment">/* format to default size, no quick */</span>
<a name="l00388"></a>00388     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> == 0x14) { <span class="comment">/* sequential DVD-RW */</span>
<a name="l00389"></a>00389         size = 128 * 1024 * 1024;
<a name="l00390"></a>00390         format_flag = 1; <span class="comment">/* write initial 128 MiB */</span>
<a name="l00391"></a>00391     } <span class="keywordflow">else</span> {
<a name="l00392"></a>00392         fprintf(stderr, <span class="stringliteral">&quot;FATAL: Can only format DVD-RW or BD\n&quot;</span>);
<a name="l00393"></a>00393         <span class="keywordflow">return</span> 0;
<a name="l00394"></a>00394     }
<a name="l00395"></a>00395     <a class="code" href="libburn_8h.html#a47b6e05ca3f53ca00f0ef4103eb5cd18" title="Control built-in signal handling.">burn_set_signal_handling</a>(<span class="stringliteral">&quot;libburner : &quot;</span>, NULL, 0x30);
<a name="l00396"></a>00396 
<a name="l00397"></a>00397     printf(<span class="stringliteral">&quot;Beginning to format media.\n&quot;</span>);
<a name="l00398"></a>00398     <a class="code" href="libburn_8h.html#a1ac5250deb1dd13d7192f5e834fd5c4d" title="Format media for use with libburn.">burn_disc_format</a>(drive, size, format_flag);
<a name="l00399"></a>00399 
<a name="l00400"></a>00400     sleep(1);
<a name="l00401"></a>00401     <span class="keywordflow">while</span> (<a class="code" href="libburn_8h.html#a992777abdf1f13f1e2c45271e43e9a3d" title="Returns the progress and status of a drive.">burn_drive_get_status</a>(drive, &amp;p) != <a class="code" href="libburn_8h.html#a3cb9c75648e773f63911b0975f67802badcb522cf8ccf1349e3d69826c3e1757f" title="The drive is not in an operation.">BURN_DRIVE_IDLE</a>) {
<a name="l00402"></a>00402         <span class="keywordflow">if</span>(p.<a class="code" href="structburn__progress.html#af093a66f1ae097ba40eeac7e1c6ac5d9" title="On write: The number of sectors.">sectors</a>&gt;0 &amp;&amp; p.<a class="code" href="structburn__progress.html#a7aa74bd989075ae02a5066003874c60d" title="On write: The current sector being processed.">sector</a>&gt;=0) <span class="comment">/* display 1 to 99 percent */</span>
<a name="l00403"></a>00403             percent = 1.0 + ((double) p.<a class="code" href="structburn__progress.html#a7aa74bd989075ae02a5066003874c60d" title="On write: The current sector being processed.">sector</a>+1.0)
<a name="l00404"></a>00404                      / ((double) p.<a class="code" href="structburn__progress.html#af093a66f1ae097ba40eeac7e1c6ac5d9" title="On write: The number of sectors.">sectors</a>) * 98.0;
<a name="l00405"></a>00405         printf(<span class="stringliteral">&quot;Formatting  ( %.1f%% done )\n&quot;</span>, percent);
<a name="l00406"></a>00406         sleep(1);
<a name="l00407"></a>00407     }
<a name="l00408"></a>00408     <span class="keywordflow">if</span> (<a class="code" href="libburn_8h.html#a98a208e78cc9126a07d1bceea775f4db">burn_is_aborting</a>(0) &gt; 0)
<a name="l00409"></a>00409         <span class="keywordflow">return</span> -1;
<a name="l00410"></a>00410     <a class="code" href="libburn_8h.html#a47b6e05ca3f53ca00f0ef4103eb5cd18" title="Control built-in signal handling.">burn_set_signal_handling</a>(<span class="stringliteral">&quot;libburner : &quot;</span>, NULL, 0x0);
<a name="l00411"></a>00411     <a class="code" href="libburn_8h.html#a1627c70c71ec5b6116f8d9d63d229285" title="Tells the MMC Profile identifier of the loaded media.">burn_disc_get_profile</a>(drive_list[0].drive, &amp;<a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a>,
<a name="l00412"></a>00412                  <a class="code" href="libburner_8c.html#a14fb7b17efb56d94fb7d794053ae045b">current_profile_name</a>);
<a name="l00413"></a>00413     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> == 0x14 || <a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> == 0x13)
<a name="l00414"></a>00414         printf(<span class="stringliteral">&quot;Media type now: %4.4xh  \&quot;%s\&quot;\n&quot;</span>,
<a name="l00415"></a>00415                  <a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a>, <a class="code" href="libburner_8c.html#a14fb7b17efb56d94fb7d794053ae045b">current_profile_name</a>);
<a name="l00416"></a>00416     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> == 0x14) {
<a name="l00417"></a>00417         fprintf(stderr,
<a name="l00418"></a>00418           <span class="stringliteral">&quot;FATAL: Failed to change media profile to desired value\n&quot;</span>);
<a name="l00419"></a>00419         <span class="keywordflow">return</span> 0;
<a name="l00420"></a>00420     }
<a name="l00421"></a>00421     <span class="keywordflow">return</span> 1;
<a name="l00422"></a>00422 }
<a name="l00423"></a>00423 
<a name="l00424"></a>00424 <span class="comment"></span>
<a name="l00425"></a>00425 <span class="comment">/** Brings preformatted track images (ISO 9660, audio, ...) onto media.</span>
<a name="l00426"></a>00426 <span class="comment">    To make sure a data image is fully readable on any Linux machine, this</span>
<a name="l00427"></a>00427 <span class="comment">    function adds 300 kiB of padding to the (usualy single) track.</span>
<a name="l00428"></a>00428 <span class="comment">    Audio tracks get padded to complete their last sector.</span>
<a name="l00429"></a>00429 <span class="comment">    A fifo of 4 MB is installed between each track and its data source.</span>
<a name="l00430"></a>00430 <span class="comment">    Each of the 4 MB buffers gets allocated automatically as soon as a track</span>
<a name="l00431"></a>00431 <span class="comment">    begins to be processed and it gets freed as soon as the track is done.</span>
<a name="l00432"></a>00432 <span class="comment">    The fifos do not wait for buffer fill but writing starts immediately.</span>
<a name="l00433"></a>00433 <span class="comment"></span>
<a name="l00434"></a>00434 <span class="comment">    In case of external signals expect abort handling of an ongoing burn to</span>
<a name="l00435"></a>00435 <span class="comment">    last up to a minute. Wait the normal burning timespan before any kill -9.</span>
<a name="l00436"></a>00436 <span class="comment"></span>
<a name="l00437"></a>00437 <span class="comment">    For simplicity, this function allows memory leaks in case of failure.</span>
<a name="l00438"></a>00438 <span class="comment">    In apps which do not abort immediately, one should clean up better.</span>
<a name="l00439"></a>00439 <span class="comment">*/</span>
<a name="l00440"></a><a class="code" href="libburner_8c.html#af9c2fc57ed6d8505b22d377daef4914b">00440</a> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#af9c2fc57ed6d8505b22d377daef4914b" title="Brings preformatted track images (ISO 9660, audio, ...) onto media.">libburner_payload</a>(<span class="keyword">struct</span> burn_drive *drive, 
<a name="l00441"></a>00441               <span class="keywordtype">char</span> <a class="code" href="libburner_8c.html#a20401aa73b1b1c04c3faddfd1647f302">source_adr</a>[][4096], <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">source_adr_count</a>,
<a name="l00442"></a>00442               <span class="keywordtype">int</span> multi, <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a0987fdf0d2c39990a6de69c649f4d470">simulate_burn</a>, <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#acdd017f7636e63e635f981e11aca9a22">all_tracks_type</a>)
<a name="l00443"></a>00443 {
<a name="l00444"></a>00444     <span class="keyword">struct </span><a class="code" href="structburn__source.html" title="Data source interface for tracks.">burn_source</a> *data_src, *fifo_src[99];
<a name="l00445"></a>00445     <span class="keyword">struct </span>burn_disc *target_disc;
<a name="l00446"></a>00446     <span class="keyword">struct </span>burn_session *session;
<a name="l00447"></a>00447     <span class="keyword">struct </span>burn_write_opts *burn_options;
<a name="l00448"></a>00448     <span class="keyword">enum</span> <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54" title="Possible status of the drive in regard to the disc in it.">burn_disc_status</a> disc_state;
<a name="l00449"></a>00449     <span class="keyword">struct </span>burn_track *track, *tracklist[99];
<a name="l00450"></a>00450     <span class="keyword">struct </span><a class="code" href="structburn__progress.html" title="Operation progress report.">burn_progress</a> progress;
<a name="l00451"></a>00451     time_t start_time;
<a name="l00452"></a>00452     <span class="keywordtype">int</span> last_sector = 0, padding = 0, trackno, unpredicted_size = 0, fd;
<a name="l00453"></a>00453     <span class="keywordtype">int</span> fifo_chunksize = 2352, fifo_chunks = 1783; <span class="comment">/* ~ 4 MB fifo */</span>
<a name="l00454"></a>00454     off_t fixed_size;
<a name="l00455"></a>00455     <span class="keywordtype">char</span> *adr, reasons[<a class="code" href="libburn_8h.html#a109ecdcd00fd30904a76c58040df9b79" title="The length of a rejection reasons string for burn_precheck_write() and burn_write_opts_auto_write_typ...">BURN_REASONS_LEN</a>];
<a name="l00456"></a>00456     <span class="keyword">struct </span>stat stbuf;
<a name="l00457"></a>00457 
<a name="l00458"></a>00458     <span class="keywordflow">if</span> (all_tracks_type != <a class="code" href="libburn_8h.html#af52cf0d05e7e207ef4a06c9caad94d9f" title="Track mode - audio 2352 bytes per sector.">BURN_AUDIO</a>) {
<a name="l00459"></a>00459         all_tracks_type = <a class="code" href="libburn_8h.html#af2e861349cb91c0af3a482225e3326ae" title="Track mode - mode 1 data 2048 bytes user data, and all the LEC money can buy.">BURN_MODE1</a>;
<a name="l00460"></a>00460         <span class="comment">/* a padding of 300 kiB helps to avoid the read-ahead bug */</span>
<a name="l00461"></a>00461         padding = 300*1024;
<a name="l00462"></a>00462         fifo_chunksize = 2048;
<a name="l00463"></a>00463         fifo_chunks = 2048; <span class="comment">/* 4 MB fifo */</span>
<a name="l00464"></a>00464     }
<a name="l00465"></a>00465 
<a name="l00466"></a>00466     target_disc = <a class="code" href="libburn_8h.html#a9514679bfc2d3c3079bb06f0ddfc2216" title="Create a new disc.">burn_disc_create</a>();
<a name="l00467"></a>00467     session = <a class="code" href="libburn_8h.html#a2dceb26e334833c240391cacfde555f7" title="Create a new session.">burn_session_create</a>();
<a name="l00468"></a>00468     <a class="code" href="libburn_8h.html#a77730a5108688fbee754fea7b56e048a" title="Add a session to a disc at a specific position, increasing the sessions&#39;s reference count...">burn_disc_add_session</a>(target_disc, session, <a class="code" href="libburn_8h.html#a57aa6e45b0236acb5fbaa9f44280f6dc">BURN_POS_END</a>);
<a name="l00469"></a>00469 
<a name="l00470"></a>00470     <span class="keywordflow">for</span> (trackno = 0 ; trackno &lt; <a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">source_adr_count</a>; trackno++) {
<a name="l00471"></a>00471       tracklist[trackno] = track = <a class="code" href="libburn_8h.html#aab87a2670415403982e499002fff0ca8" title="Create a track.">burn_track_create</a>();
<a name="l00472"></a>00472       <a class="code" href="libburn_8h.html#aef2fd880f00065082691a848edcaf01e" title="Define the data in a track.">burn_track_define_data</a>(track, 0, padding, 1, all_tracks_type);
<a name="l00473"></a>00473 
<a name="l00474"></a>00474       <span class="comment">/* Open file descriptor to source of track data */</span>
<a name="l00475"></a>00475       adr = source_adr[trackno];
<a name="l00476"></a>00476       fixed_size = 0;
<a name="l00477"></a>00477       <span class="keywordflow">if</span> (adr[0] == <span class="charliteral">&#39;-&#39;</span> &amp;&amp; adr[1] == 0) {
<a name="l00478"></a>00478         fd = 0;
<a name="l00479"></a>00479       } <span class="keywordflow">else</span> {
<a name="l00480"></a>00480         fd = open(adr, O_RDONLY);
<a name="l00481"></a>00481         <span class="keywordflow">if</span> (fd&gt;=0)
<a name="l00482"></a>00482             <span class="keywordflow">if</span> (fstat(fd,&amp;stbuf)!=-1)
<a name="l00483"></a>00483                 <span class="keywordflow">if</span>((stbuf.st_mode&amp;S_IFMT)==S_IFREG)
<a name="l00484"></a>00484                     fixed_size = stbuf.st_size;
<a name="l00485"></a>00485       }
<a name="l00486"></a>00486       <span class="keywordflow">if</span> (fixed_size==0)
<a name="l00487"></a>00487         unpredicted_size = 1;
<a name="l00488"></a>00488 
<a name="l00489"></a>00489       <span class="comment">/* Convert this filedescriptor into a burn_source object */</span>
<a name="l00490"></a>00490       data_src = NULL;
<a name="l00491"></a>00491       <span class="keywordflow">if</span> (fd&gt;=0)
<a name="l00492"></a>00492         data_src = <a class="code" href="libburn_8h.html#a2e1504f4c949b13cea988e31af9c150a" title="Creates a data source for an image file (a track) from an open readable filedescriptor, an eventually open readable subcodes file descriptor and eventually a fixed size in bytes.">burn_fd_source_new</a>(fd, -1, fixed_size);
<a name="l00493"></a>00493       <span class="keywordflow">if</span> (data_src == NULL) {
<a name="l00494"></a>00494         fprintf(stderr,
<a name="l00495"></a>00495                <span class="stringliteral">&quot;FATAL: Could not open data source &#39;%s&#39;.\n&quot;</span>,adr);
<a name="l00496"></a>00496         <span class="keywordflow">if</span>(errno!=0)
<a name="l00497"></a>00497             fprintf(stderr,<span class="stringliteral">&quot;(Most recent system error: %s )\n&quot;</span>,
<a name="l00498"></a>00498                 strerror(errno));
<a name="l00499"></a>00499         <span class="keywordflow">return</span> 0;
<a name="l00500"></a>00500       }
<a name="l00501"></a>00501       <span class="comment">/* Install a fifo object on top of that data source object */</span>
<a name="l00502"></a>00502       fifo_src[trackno] = <a class="code" href="libburn_8h.html#a2d7a2faac8565ddd40d9e6ddae0bd922" title="Creates a fifo which acts as proxy for an already existing data source.">burn_fifo_source_new</a>(data_src,
<a name="l00503"></a>00503                     fifo_chunksize, fifo_chunks, 0);
<a name="l00504"></a>00504       <span class="keywordflow">if</span> (fifo_src[trackno] == NULL) {
<a name="l00505"></a>00505         fprintf(stderr,
<a name="l00506"></a>00506             <span class="stringliteral">&quot;FATAL: Could not create fifo object of 4 MB\n&quot;</span>);
<a name="l00507"></a>00507         <span class="keywordflow">return</span> 0;
<a name="l00508"></a>00508       }
<a name="l00509"></a>00509 
<a name="l00510"></a>00510       <span class="comment">/* Use the fifo object as data source for the track */</span>
<a name="l00511"></a>00511       <span class="keywordflow">if</span> (<a class="code" href="libburn_8h.html#a27400c91868946c04b013c2cc2ac632a" title="Set the track&#39;s data source.">burn_track_set_source</a>(track, fifo_src[trackno])
<a name="l00512"></a>00512                              != <a class="code" href="libburn_8h.html#aa5ddf1fe21e47ff4d4a44262c1d7da9ba936b5414e25492f45a3f240941f3d9a1" title="The source is ok.">BURN_SOURCE_OK</a>) {
<a name="l00513"></a>00513         fprintf(stderr,
<a name="l00514"></a>00514                <span class="stringliteral">&quot;FATAL: Cannot attach source object to track object\n&quot;</span>);
<a name="l00515"></a>00515         <span class="keywordflow">return</span> 0;
<a name="l00516"></a>00516       }
<a name="l00517"></a>00517 
<a name="l00518"></a>00518       <a class="code" href="libburn_8h.html#a2062793258361e9e84e7ddbf5f9ab06a" title="Add a track to a session at specified position.">burn_session_add_track</a>(session, track, <a class="code" href="libburn_8h.html#a57aa6e45b0236acb5fbaa9f44280f6dc">BURN_POS_END</a>);
<a name="l00519"></a>00519       printf(<span class="stringliteral">&quot;Track %d : source is &#39;%s&#39;\n&quot;</span>, trackno+1, adr);
<a name="l00520"></a>00520 
<a name="l00521"></a>00521       <span class="comment">/* Give up local reference to the data burn_source object */</span>
<a name="l00522"></a>00522       <a class="code" href="libburn_8h.html#a1a03f8b3088b8ce6305e7a48c3e034eb" title="Free a burn_source (decrease its refcount and maybe free it)">burn_source_free</a>(data_src);
<a name="l00523"></a>00523       
<a name="l00524"></a>00524     } <span class="comment">/* trackno loop end */</span>
<a name="l00525"></a>00525 
<a name="l00526"></a>00526     <span class="comment">/* Evaluate drive and media */</span>
<a name="l00527"></a>00527     disc_state = <a class="code" href="libburn_8h.html#ac009cc9dfe07c8c0b67f528a369fd511" title="Returns what kind of disc a drive is holding.">burn_disc_get_status</a>(drive);
<a name="l00528"></a>00528     <span class="keywordflow">if</span> (disc_state != <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54a59c757934ef338281512efce4ab6fd93" title="The drive holds a blank disc.">BURN_DISC_BLANK</a> &amp;&amp;
<a name="l00529"></a>00529         disc_state != <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54acda6fac8462fa9affb4bff80daa2ab3f" title="There is an incomplete disc in the drive.">BURN_DISC_APPENDABLE</a>) {
<a name="l00530"></a>00530         <span class="keywordflow">if</span> (disc_state == <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54ae0ea0a584e319ee775062c88975c93cd" title="There is a disc with data on it in the drive.">BURN_DISC_FULL</a>) {
<a name="l00531"></a>00531             fprintf(stderr, <span class="stringliteral">&quot;FATAL: Closed media with data detected. Need blank or appendable media.\n&quot;</span>);
<a name="l00532"></a>00532             <span class="keywordflow">if</span> (<a class="code" href="libburn_8h.html#a7838224062ed72305f3c6b1055cb1a98" title="Tells whether a disc can be erased or not.">burn_disc_erasable</a>(drive))
<a name="l00533"></a>00533                 fprintf(stderr, <span class="stringliteral">&quot;HINT: Try --blank_fast\n\n&quot;</span>);
<a name="l00534"></a>00534         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (disc_state == <a class="code" href="libburn_8h.html#ad6002e7587373e7e9a9efbd22c1e6c54a23eef5011f3aa95ce1858a2930c22c69" title="There is no disc at all in the drive.">BURN_DISC_EMPTY</a>) 
<a name="l00535"></a>00535             fprintf(stderr,<span class="stringliteral">&quot;FATAL: No media detected in drive\n&quot;</span>);
<a name="l00536"></a>00536         <span class="keywordflow">else</span>
<a name="l00537"></a>00537             fprintf(stderr,
<a name="l00538"></a>00538              <span class="stringliteral">&quot;FATAL: Cannot recognize state of drive and media\n&quot;</span>);
<a name="l00539"></a>00539         <span class="keywordflow">return</span> 0;
<a name="l00540"></a>00540     }
<a name="l00541"></a>00541 
<a name="l00542"></a>00542     burn_options = <a class="code" href="libburn_8h.html#ad62ba8f5344c36e2faa9aa6208751e0a" title="Creates a write_opts struct for burning to the specified drive.">burn_write_opts_new</a>(drive);
<a name="l00543"></a>00543     <a class="code" href="libburn_8h.html#a8e4ed29facd80f19c866b3686dea125f" title="Sets whether to use opc or not with the write_opts struct.">burn_write_opts_set_perform_opc</a>(burn_options, 0);
<a name="l00544"></a>00544     <a class="code" href="libburn_8h.html#ad04dc50d1223d78a8e8c3134df96fd82" title="Sets the multi flag which eventually marks the emerging session as not being the last one and thus cr...">burn_write_opts_set_multi</a>(burn_options, !!multi);
<a name="l00545"></a>00545     <span class="keywordflow">if</span>(simulate_burn)
<a name="l00546"></a>00546         printf(<span class="stringliteral">&quot;\n*** Will TRY to SIMULATE burning ***\n\n&quot;</span>);
<a name="l00547"></a>00547     <a class="code" href="libburn_8h.html#a05f68d91d1074a103fa8e17bb664b6d8" title="Sets the simulate value for the write_opts struct .">burn_write_opts_set_simulate</a>(burn_options, simulate_burn);
<a name="l00548"></a>00548     <a class="code" href="libburn_8h.html#a62aa53e04ff9fb848178ab85d38a9c5a" title="Sets drive read and write speed Note: &quot;k&quot; is 1000, not 1024.">burn_drive_set_speed</a>(drive, 0, 0);
<a name="l00549"></a>00549     <a class="code" href="libburn_8h.html#a3fdc2e3cc51bec2072ab91b99d4e52d9" title="Controls buffer underrun prevention.">burn_write_opts_set_underrun_proof</a>(burn_options, 1);
<a name="l00550"></a>00550     <span class="keywordflow">if</span> (<a class="code" href="libburn_8h.html#a88a9d0adaf11e19cb4ed8b08f7740b5b" title="As an alternative to burn_write_opts_set_write_type() this function tries to find a suitable write ty...">burn_write_opts_auto_write_type</a>(burn_options, target_disc,
<a name="l00551"></a>00551                     reasons, 0) == <a class="code" href="libburn_8h.html#a98506c0d72c878ea6cbecc4004451d9baf43fb685b48fdc83337465457eec54fd" title="In replies this indicates that not any writing will work.">BURN_WRITE_NONE</a>) {
<a name="l00552"></a>00552         fprintf(stderr, <span class="stringliteral">&quot;FATAL: Failed to find a suitable write mode with this media.\n&quot;</span>);
<a name="l00553"></a>00553         fprintf(stderr, <span class="stringliteral">&quot;Reasons given:\n%s\n&quot;</span>, reasons);
<a name="l00554"></a>00554         <span class="keywordflow">return</span> 0;
<a name="l00555"></a>00555     }
<a name="l00556"></a>00556     <a class="code" href="libburn_8h.html#a47b6e05ca3f53ca00f0ef4103eb5cd18" title="Control built-in signal handling.">burn_set_signal_handling</a>(<span class="stringliteral">&quot;libburner : &quot;</span>, NULL, 0x30);
<a name="l00557"></a>00557 
<a name="l00558"></a>00558     printf(<span class="stringliteral">&quot;Burning starts. With e.g. 4x media expect up to a minute of zero progress.\n&quot;</span>);
<a name="l00559"></a>00559     start_time = time(0);
<a name="l00560"></a>00560     <a class="code" href="libburn_8h.html#a75d3d59e9c3cd7cd42c9735bee83bd91" title="Write a disc in the drive.">burn_disc_write</a>(burn_options, target_disc);
<a name="l00561"></a>00561 
<a name="l00562"></a>00562     <a class="code" href="libburn_8h.html#a1336283a8e59fe7ac187243350e21866" title="Frees a write_opts struct created with burn_write_opts_new.">burn_write_opts_free</a>(burn_options);
<a name="l00563"></a>00563     <span class="keywordflow">while</span> (<a class="code" href="libburn_8h.html#a992777abdf1f13f1e2c45271e43e9a3d" title="Returns the progress and status of a drive.">burn_drive_get_status</a>(drive, NULL) == <a class="code" href="libburn_8h.html#a3cb9c75648e773f63911b0975f67802ba9c16cf7335531f54df68a0b280c75898" title="The library is spawning the processes to handle a pending operation (A read/write/etc is about to sta...">BURN_DRIVE_SPAWNING</a>)
<a name="l00564"></a>00564         usleep(100002);
<a name="l00565"></a>00565     <span class="keywordflow">while</span> (<a class="code" href="libburn_8h.html#a992777abdf1f13f1e2c45271e43e9a3d" title="Returns the progress and status of a drive.">burn_drive_get_status</a>(drive, &amp;progress) != <a class="code" href="libburn_8h.html#a3cb9c75648e773f63911b0975f67802badcb522cf8ccf1349e3d69826c3e1757f" title="The drive is not in an operation.">BURN_DRIVE_IDLE</a>) {
<a name="l00566"></a>00566         <span class="keywordflow">if</span> (progress.<a class="code" href="structburn__progress.html#af093a66f1ae097ba40eeac7e1c6ac5d9" title="On write: The number of sectors.">sectors</a> &lt;= 0 ||
<a name="l00567"></a>00567             (progress.<a class="code" href="structburn__progress.html#a7aa74bd989075ae02a5066003874c60d" title="On write: The current sector being processed.">sector</a> &gt;= progress.<a class="code" href="structburn__progress.html#af093a66f1ae097ba40eeac7e1c6ac5d9" title="On write: The number of sectors.">sectors</a> - 1 &amp;&amp;
<a name="l00568"></a>00568                  !unpredicted_size) ||
<a name="l00569"></a>00569             (unpredicted_size &amp;&amp; progress.<a class="code" href="structburn__progress.html#a7aa74bd989075ae02a5066003874c60d" title="On write: The current sector being processed.">sector</a> == last_sector))
<a name="l00570"></a>00570             printf(
<a name="l00571"></a>00571                  <span class="stringliteral">&quot;Thank you for being patient since %d seconds.&quot;</span>,
<a name="l00572"></a>00572                  (<span class="keywordtype">int</span>) (time(0) - start_time));
<a name="l00573"></a>00573         <span class="keywordflow">else</span> <span class="keywordflow">if</span>(unpredicted_size)
<a name="l00574"></a>00574             printf(<span class="stringliteral">&quot;Track %d : sector %d&quot;</span>, progress.<a class="code" href="structburn__progress.html#a93666a25e6d3611f9384e89fe2a2f65e" title="Current track.">track</a>+1,
<a name="l00575"></a>00575                 progress.<a class="code" href="structburn__progress.html#a7aa74bd989075ae02a5066003874c60d" title="On write: The current sector being processed.">sector</a>);
<a name="l00576"></a>00576         <span class="keywordflow">else</span>
<a name="l00577"></a>00577             printf(<span class="stringliteral">&quot;Track %d : sector %d of %d&quot;</span>,progress.<a class="code" href="structburn__progress.html#a93666a25e6d3611f9384e89fe2a2f65e" title="Current track.">track</a>+1,
<a name="l00578"></a>00578                 progress.<a class="code" href="structburn__progress.html#a7aa74bd989075ae02a5066003874c60d" title="On write: The current sector being processed.">sector</a>, progress.<a class="code" href="structburn__progress.html#af093a66f1ae097ba40eeac7e1c6ac5d9" title="On write: The number of sectors.">sectors</a>);
<a name="l00579"></a>00579         last_sector = progress.<a class="code" href="structburn__progress.html#a7aa74bd989075ae02a5066003874c60d" title="On write: The current sector being processed.">sector</a>;
<a name="l00580"></a>00580         <span class="keywordflow">if</span> (progress.<a class="code" href="structburn__progress.html#a93666a25e6d3611f9384e89fe2a2f65e" title="Current track.">track</a> &gt;= 0 &amp;&amp; progress.<a class="code" href="structburn__progress.html#a93666a25e6d3611f9384e89fe2a2f65e" title="Current track.">track</a> &lt; source_adr_count) {
<a name="l00581"></a>00581             <span class="keywordtype">int</span> size, free_bytes, ret;
<a name="l00582"></a>00582             <span class="keywordtype">char</span> *status_text;
<a name="l00583"></a>00583     
<a name="l00584"></a>00584             ret = <a class="code" href="libburn_8h.html#af655df46b73a4d774cc1d27b0c57677d" title="Inquires state and fill parameters of a fifo burn_source which was created by burn_fifo_source_new() ...">burn_fifo_inquire_status</a>(
<a name="l00585"></a>00585                 fifo_src[progress.<a class="code" href="structburn__progress.html#a93666a25e6d3611f9384e89fe2a2f65e" title="Current track.">track</a>], &amp;size, &amp;free_bytes,
<a name="l00586"></a>00586                 &amp;status_text);
<a name="l00587"></a>00587             <span class="keywordflow">if</span> (ret &gt;= 0 ) 
<a name="l00588"></a>00588                 printf(<span class="stringliteral">&quot;  [fifo %s, %2d%% fill]&quot;</span>, status_text,
<a name="l00589"></a>00589                     (<span class="keywordtype">int</span>) (100.0 - 100.0 *
<a name="l00590"></a>00590                         ((<span class="keywordtype">double</span>) free_bytes) /
<a name="l00591"></a>00591                         (<span class="keywordtype">double</span>) size));
<a name="l00592"></a>00592         } 
<a name="l00593"></a>00593         printf(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00594"></a>00594         sleep(1);
<a name="l00595"></a>00595     }
<a name="l00596"></a>00596     printf(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00597"></a>00597 
<a name="l00598"></a>00598     <span class="keywordflow">for</span> (trackno = 0 ; trackno &lt; <a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">source_adr_count</a>; trackno++) {
<a name="l00599"></a>00599         <a class="code" href="libburn_8h.html#a1a03f8b3088b8ce6305e7a48c3e034eb" title="Free a burn_source (decrease its refcount and maybe free it)">burn_source_free</a>(fifo_src[trackno]);
<a name="l00600"></a>00600         <a class="code" href="libburn_8h.html#a105c516de4f9242d91f7e92d0b399110" title="Free a track.">burn_track_free</a>(tracklist[trackno]);
<a name="l00601"></a>00601     }
<a name="l00602"></a>00602     <a class="code" href="libburn_8h.html#a21765aec4a5b1a9c21c027f855f9c2a0" title="Free a session (and decrease reference count on all tracks inside)">burn_session_free</a>(session);
<a name="l00603"></a>00603     <a class="code" href="libburn_8h.html#aca06a415d81da71a3fd3aad31e83c698" title="Delete disc and decrease the reference count on all its sessions.">burn_disc_free</a>(target_disc);
<a name="l00604"></a>00604     <span class="keywordflow">if</span> (<a class="code" href="libburn_8h.html#a98a208e78cc9126a07d1bceea775f4db">burn_is_aborting</a>(0) &gt; 0)
<a name="l00605"></a>00605         <span class="keywordflow">return</span> -1;
<a name="l00606"></a>00606     <span class="keywordflow">if</span> (multi &amp;&amp; <a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> != 0x1a &amp;&amp; <a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> != 0x13 &amp;&amp;
<a name="l00607"></a>00607         <a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> != 0x12 &amp;&amp; <a class="code" href="libburner_8c.html#aa1a3fe5ef89cfc5713ab70e8b3d41043" title="A number and a text describing the type of media in aquired drive.">current_profile</a> != 0x43) 
<a name="l00608"></a>00608             <span class="comment">/* not with DVD+RW, formatted DVD-RW, DVD-RAM, BD-RE */</span>
<a name="l00609"></a>00609         printf(<span class="stringliteral">&quot;NOTE: Media left appendable.\n&quot;</span>);
<a name="l00610"></a>00610     <span class="keywordflow">if</span> (simulate_burn)
<a name="l00611"></a>00611         printf(<span class="stringliteral">&quot;\n*** Did TRY to SIMULATE burning ***\n\n&quot;</span>);
<a name="l00612"></a>00612     <span class="keywordflow">return</span> 1;
<a name="l00613"></a>00613 }
<a name="l00614"></a>00614 
<a name="l00615"></a>00615 <span class="comment"></span>
<a name="l00616"></a>00616 <span class="comment">/** The setup parameters of libburner */</span>
<a name="l00617"></a><a class="code" href="libburner_8c.html#adbe410a004b2aefa8868608beb2e5df1">00617</a> <span class="keyword">static</span> <span class="keywordtype">char</span> <a class="code" href="libburner_8c.html#adbe410a004b2aefa8868608beb2e5df1" title="The setup parameters of libburner.">drive_adr</a>[<a class="code" href="libburn_8h.html#a489ca2111726a034324275aca4ed069c" title="Maximum length+1 to expect with a drive device file address string.">BURN_DRIVE_ADR_LEN</a>] = {<span class="stringliteral">&quot;&quot;</span>};
<a name="l00618"></a><a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">00618</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a> = 0;
<a name="l00619"></a><a class="code" href="libburner_8c.html#aec8a1ef7e11653bc93fe1d5b2c63c9d3">00619</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#aec8a1ef7e11653bc93fe1d5b2c63c9d3">do_blank</a> = 0;
<a name="l00620"></a><a class="code" href="libburner_8c.html#a20401aa73b1b1c04c3faddfd1647f302">00620</a> <span class="keyword">static</span> <span class="keywordtype">char</span> <a class="code" href="libburner_8c.html#a20401aa73b1b1c04c3faddfd1647f302">source_adr</a>[99][4096];
<a name="l00621"></a><a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">00621</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">source_adr_count</a> = 0;
<a name="l00622"></a><a class="code" href="libburner_8c.html#a8e824cc51e6e6cfc91ac1df7830a70ed">00622</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a8e824cc51e6e6cfc91ac1df7830a70ed">do_multi</a> = 0;
<a name="l00623"></a><a class="code" href="libburner_8c.html#a0987fdf0d2c39990a6de69c649f4d470">00623</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a0987fdf0d2c39990a6de69c649f4d470">simulate_burn</a> = 0;
<a name="l00624"></a><a class="code" href="libburner_8c.html#acdd017f7636e63e635f981e11aca9a22">00624</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#acdd017f7636e63e635f981e11aca9a22">all_tracks_type</a> = <a class="code" href="libburn_8h.html#af2e861349cb91c0af3a482225e3326ae" title="Track mode - mode 1 data 2048 bytes user data, and all the LEC money can buy.">BURN_MODE1</a>;
<a name="l00625"></a>00625 
<a name="l00626"></a>00626 <span class="comment"></span>
<a name="l00627"></a>00627 <span class="comment">/** Converts command line arguments into above setup parameters.</span>
<a name="l00628"></a>00628 <span class="comment">*/</span>
<a name="l00629"></a><a class="code" href="libburner_8c.html#a67980a9cee509cf714f67aa96a47c75d">00629</a> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a67980a9cee509cf714f67aa96a47c75d" title="Converts command line arguments into above setup parameters.">libburner_setup</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
<a name="l00630"></a>00630 {
<a name="l00631"></a>00631     <span class="keywordtype">int</span> i, insuffient_parameters = 0, print_help = 0;
<a name="l00632"></a>00632 
<a name="l00633"></a>00633     <span class="keywordflow">for</span> (i = 1; i &lt; argc; ++i) {
<a name="l00634"></a>00634         <span class="keywordflow">if</span> (!strcmp(argv[i], <span class="stringliteral">&quot;--audio&quot;</span>)) {
<a name="l00635"></a>00635             <a class="code" href="libburner_8c.html#acdd017f7636e63e635f981e11aca9a22">all_tracks_type</a> = <a class="code" href="libburn_8h.html#af52cf0d05e7e207ef4a06c9caad94d9f" title="Track mode - audio 2352 bytes per sector.">BURN_AUDIO</a>;
<a name="l00636"></a>00636 
<a name="l00637"></a>00637         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(argv[i], <span class="stringliteral">&quot;--blank_fast&quot;</span>)) {
<a name="l00638"></a>00638             <a class="code" href="libburner_8c.html#aec8a1ef7e11653bc93fe1d5b2c63c9d3">do_blank</a> = 1;
<a name="l00639"></a>00639 
<a name="l00640"></a>00640         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(argv[i], <span class="stringliteral">&quot;--blank_full&quot;</span>)) {
<a name="l00641"></a>00641             <a class="code" href="libburner_8c.html#aec8a1ef7e11653bc93fe1d5b2c63c9d3">do_blank</a> = 2;
<a name="l00642"></a>00642 
<a name="l00643"></a>00643         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(argv[i], <span class="stringliteral">&quot;--burn_for_real&quot;</span>)) {
<a name="l00644"></a>00644             <a class="code" href="libburner_8c.html#a0987fdf0d2c39990a6de69c649f4d470">simulate_burn</a> = 0;
<a name="l00645"></a>00645 
<a name="l00646"></a>00646         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(argv[i], <span class="stringliteral">&quot;--drive&quot;</span>)) {
<a name="l00647"></a>00647             ++i;
<a name="l00648"></a>00648             <span class="keywordflow">if</span> (i &gt;= argc) {
<a name="l00649"></a>00649                 fprintf(stderr,<span class="stringliteral">&quot;--drive requires an argument\n&quot;</span>);
<a name="l00650"></a>00650                 <span class="keywordflow">return</span> 1;
<a name="l00651"></a>00651             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-&quot;</span>) == 0) {
<a name="l00652"></a>00652                 <a class="code" href="libburner_8c.html#adbe410a004b2aefa8868608beb2e5df1" title="The setup parameters of libburner.">drive_adr</a>[0] = 0;
<a name="l00653"></a>00653                 <a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a> = -1;
<a name="l00654"></a>00654             } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (isdigit(argv[i][0])) {
<a name="l00655"></a>00655                 <a class="code" href="libburner_8c.html#adbe410a004b2aefa8868608beb2e5df1" title="The setup parameters of libburner.">drive_adr</a>[0] = 0;
<a name="l00656"></a>00656                 <a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a> = atoi(argv[i]);
<a name="l00657"></a>00657             } <span class="keywordflow">else</span> {
<a name="l00658"></a>00658                 <span class="keywordflow">if</span>(strlen(argv[i]) &gt;= <a class="code" href="libburn_8h.html#a489ca2111726a034324275aca4ed069c" title="Maximum length+1 to expect with a drive device file address string.">BURN_DRIVE_ADR_LEN</a>) {
<a name="l00659"></a>00659                     fprintf(stderr,<span class="stringliteral">&quot;--drive address too long (max. %d)\n&quot;</span>,
<a name="l00660"></a>00660                             <a class="code" href="libburn_8h.html#a489ca2111726a034324275aca4ed069c" title="Maximum length+1 to expect with a drive device file address string.">BURN_DRIVE_ADR_LEN</a>-1);
<a name="l00661"></a>00661                     <span class="keywordflow">return</span> 2;
<a name="l00662"></a>00662                 }
<a name="l00663"></a>00663                 strcpy(<a class="code" href="libburner_8c.html#adbe410a004b2aefa8868608beb2e5df1" title="The setup parameters of libburner.">drive_adr</a>, argv[i]);
<a name="l00664"></a>00664             }
<a name="l00665"></a>00665         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((!strcmp(argv[i], <span class="stringliteral">&quot;--format_overwrite&quot;</span>)) ||
<a name="l00666"></a>00666            (!strcmp(argv[i], <span class="stringliteral">&quot;--format&quot;</span>))) {
<a name="l00667"></a>00667             <a class="code" href="libburner_8c.html#aec8a1ef7e11653bc93fe1d5b2c63c9d3">do_blank</a> = 101;
<a name="l00668"></a>00668 
<a name="l00669"></a>00669         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(argv[i], <span class="stringliteral">&quot;--multi&quot;</span>)) {
<a name="l00670"></a>00670         <a class="code" href="libburner_8c.html#a8e824cc51e6e6cfc91ac1df7830a70ed">do_multi</a> = 1;
<a name="l00671"></a>00671 
<a name="l00672"></a>00672     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(argv[i], <span class="stringliteral">&quot;--stdin_size&quot;</span>)) { <span class="comment">/* obsoleted */</span>
<a name="l00673"></a>00673         i++;
<a name="l00674"></a>00674 
<a name="l00675"></a>00675         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(argv[i], <span class="stringliteral">&quot;--try_to_simulate&quot;</span>)) {
<a name="l00676"></a>00676             <a class="code" href="libburner_8c.html#a0987fdf0d2c39990a6de69c649f4d470">simulate_burn</a> = 1;
<a name="l00677"></a>00677 
<a name="l00678"></a>00678         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(argv[i], <span class="stringliteral">&quot;--help&quot;</span>)) {
<a name="l00679"></a>00679             print_help = 1;
<a name="l00680"></a>00680 
<a name="l00681"></a>00681         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strncmp(argv[i], <span class="stringliteral">&quot;--&quot;</span>,2)) {
<a name="l00682"></a>00682             fprintf(stderr, <span class="stringliteral">&quot;Unidentified option: %s\n&quot;</span>, argv[i]);
<a name="l00683"></a>00683             <span class="keywordflow">return</span> 7;
<a name="l00684"></a>00684         } <span class="keywordflow">else</span> {
<a name="l00685"></a>00685             <span class="keywordflow">if</span>(strlen(argv[i]) &gt;= 4096) {
<a name="l00686"></a>00686                 fprintf(stderr, <span class="stringliteral">&quot;Source address too long (max. %d)\n&quot;</span>, 4096-1);
<a name="l00687"></a>00687                 <span class="keywordflow">return</span> 5;
<a name="l00688"></a>00688             }
<a name="l00689"></a>00689             <span class="keywordflow">if</span>(<a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">source_adr_count</a> &gt;= 99) {
<a name="l00690"></a>00690                 fprintf(stderr, <span class="stringliteral">&quot;Too many tracks (max. 99)\n&quot;</span>);
<a name="l00691"></a>00691                 <span class="keywordflow">return</span> 6;
<a name="l00692"></a>00692             }
<a name="l00693"></a>00693             strcpy(<a class="code" href="libburner_8c.html#a20401aa73b1b1c04c3faddfd1647f302">source_adr</a>[<a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">source_adr_count</a>], argv[i]);
<a name="l00694"></a>00694             source_adr_count++;
<a name="l00695"></a>00695         }
<a name="l00696"></a>00696     }
<a name="l00697"></a>00697     insuffient_parameters = 1;
<a name="l00698"></a>00698     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a> &lt; 0)
<a name="l00699"></a>00699         insuffient_parameters = 0;
<a name="l00700"></a>00700     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">source_adr_count</a> &gt; 0)
<a name="l00701"></a>00701         insuffient_parameters = 0; 
<a name="l00702"></a>00702     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aec8a1ef7e11653bc93fe1d5b2c63c9d3">do_blank</a>)
<a name="l00703"></a>00703         insuffient_parameters = 0;
<a name="l00704"></a>00704     <span class="keywordflow">if</span> (print_help || insuffient_parameters ) {
<a name="l00705"></a>00705         printf(<span class="stringliteral">&quot;Usage: %s\n&quot;</span>, argv[0]);
<a name="l00706"></a>00706         printf(<span class="stringliteral">&quot;       [--drive &lt;address&gt;|&lt;driveno&gt;|\&quot;-\&quot;]  [--audio]\n&quot;</span>);
<a name="l00707"></a>00707         printf(<span class="stringliteral">&quot;       [--blank_fast|--blank_full|--format]  [--try_to_simulate]\n&quot;</span>);
<a name="l00708"></a>00708         printf(<span class="stringliteral">&quot;       [--multi]  [&lt;one or more imagefiles&gt;|\&quot;-\&quot;]\n&quot;</span>);
<a name="l00709"></a>00709         printf(<span class="stringliteral">&quot;Examples\n&quot;</span>);
<a name="l00710"></a>00710         printf(<span class="stringliteral">&quot;A bus scan (needs rw-permissions to see a drive):\n&quot;</span>);
<a name="l00711"></a>00711         printf(<span class="stringliteral">&quot;  %s --drive -\n&quot;</span>,argv[0]);
<a name="l00712"></a>00712         printf(<span class="stringliteral">&quot;Burn a file to drive chosen by number, leave appendable:\n&quot;</span>);
<a name="l00713"></a>00713         printf(<span class="stringliteral">&quot;  %s --drive 0 --multi my_image_file\n&quot;</span>, argv[0]);
<a name="l00714"></a>00714         printf(<span class="stringliteral">&quot;Burn a file to drive chosen by persistent address, close:\n&quot;</span>);
<a name="l00715"></a>00715         printf(<span class="stringliteral">&quot;  %s --drive /dev/hdc my_image_file\n&quot;</span>, argv[0]);
<a name="l00716"></a>00716         printf(<span class="stringliteral">&quot;Blank a used CD-RW (is combinable with burning in one run):\n&quot;</span>);
<a name="l00717"></a>00717         printf(<span class="stringliteral">&quot;  %s --drive /dev/hdc --blank_fast\n&quot;</span>,argv[0]);
<a name="l00718"></a>00718         printf(<span class="stringliteral">&quot;Blank a used DVD-RW (is combinable with burning in one run):\n&quot;</span>);
<a name="l00719"></a>00719         printf(<span class="stringliteral">&quot;  %s --drive /dev/hdc --blank_full\n&quot;</span>,argv[0]);
<a name="l00720"></a>00720         printf(<span class="stringliteral">&quot;Format a DVD-RW, BD-RE or BD-R:\n&quot;</span>);
<a name="l00721"></a>00721         printf(<span class="stringliteral">&quot;  %s --drive /dev/hdc --format\n&quot;</span>, argv[0]);
<a name="l00722"></a>00722         printf(<span class="stringliteral">&quot;Burn two audio tracks (to CD only):\n&quot;</span>);
<a name="l00723"></a>00723         printf(<span class="stringliteral">&quot;  lame --decode -t /path/to/track1.mp3 track1.cd\n&quot;</span>);
<a name="l00724"></a>00724         printf(<span class="stringliteral">&quot;  test/dewav /path/to/track2.wav -o track2.cd\n&quot;</span>);
<a name="l00725"></a>00725         printf(<span class="stringliteral">&quot;  %s --drive /dev/hdc --audio track1.cd track2.cd\n&quot;</span>, argv[0]);
<a name="l00726"></a>00726         printf(<span class="stringliteral">&quot;Burn a compressed afio archive on-the-fly:\n&quot;</span>);
<a name="l00727"></a>00727         printf(<span class="stringliteral">&quot;  ( cd my_directory ; find . -print | afio -oZ - ) | \\\n&quot;</span>);
<a name="l00728"></a>00728         printf(<span class="stringliteral">&quot;  %s --drive /dev/hdc -\n&quot;</span>, argv[0]);
<a name="l00729"></a>00729         printf(<span class="stringliteral">&quot;To be read from *not mounted* media via: afio -tvZ /dev/hdc\n&quot;</span>);
<a name="l00730"></a>00730         <span class="keywordflow">if</span> (insuffient_parameters)
<a name="l00731"></a>00731             <span class="keywordflow">return</span> 6;
<a name="l00732"></a>00732     }
<a name="l00733"></a>00733     <span class="keywordflow">return</span> 0;
<a name="l00734"></a>00734 }
<a name="l00735"></a>00735 
<a name="l00736"></a>00736 
<a name="l00737"></a><a class="code" href="libburner_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">00737</a> <span class="keywordtype">int</span> <a class="code" href="libburner_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
<a name="l00738"></a>00738 {
<a name="l00739"></a>00739     <span class="keywordtype">int</span> ret;
<a name="l00740"></a>00740 
<a name="l00741"></a>00741     <span class="comment">/* A warning to programmers who start their own projekt from here. */</span>
<a name="l00742"></a>00742     <span class="keywordflow">if</span> (<span class="keyword">sizeof</span>(off_t) != 8) {
<a name="l00743"></a>00743          fprintf(stderr,
<a name="l00744"></a>00744        <span class="stringliteral">&quot;\nFATAL: Compile time misconfiguration. off_t is not 64 bit.\n\n&quot;</span>);
<a name="l00745"></a>00745          exit(39);
<a name="l00746"></a>00746     }
<a name="l00747"></a>00747 
<a name="l00748"></a>00748     ret = <a class="code" href="libburner_8c.html#a67980a9cee509cf714f67aa96a47c75d" title="Converts command line arguments into above setup parameters.">libburner_setup</a>(argc, argv);
<a name="l00749"></a>00749     <span class="keywordflow">if</span> (ret)
<a name="l00750"></a>00750         exit(ret);
<a name="l00751"></a>00751 
<a name="l00752"></a>00752     printf(<span class="stringliteral">&quot;Initializing libburnia-project.org ...\n&quot;</span>);
<a name="l00753"></a>00753     <span class="keywordflow">if</span> (<a class="code" href="libburn_8h.html#a53b82b88a6ebfa788ace50d890080bc6" title="Initialize the library.">burn_initialize</a>())
<a name="l00754"></a>00754         printf(<span class="stringliteral">&quot;Done\n&quot;</span>);
<a name="l00755"></a>00755     <span class="keywordflow">else</span> {
<a name="l00756"></a>00756         printf(<span class="stringliteral">&quot;FAILED\n&quot;</span>);
<a name="l00757"></a>00757         fprintf(stderr,<span class="stringliteral">&quot;\nFATAL: Failed to initialize.\n&quot;</span>);
<a name="l00758"></a>00758         exit(33);
<a name="l00759"></a>00759     }
<a name="l00760"></a>00760 
<a name="l00761"></a>00761     <span class="comment">/* Print messages of severity SORRY or more directly to stderr */</span>
<a name="l00762"></a>00762     <a class="code" href="libburn_8h.html#a634106ec331c7b7db40a142c467cfb48" title="Control queueing and stderr printing of messages from libburn.">burn_msgs_set_severities</a>(<span class="stringliteral">&quot;NEVER&quot;</span>, <span class="stringliteral">&quot;SORRY&quot;</span>, <span class="stringliteral">&quot;libburner : &quot;</span>);
<a name="l00763"></a>00763 
<a name="l00764"></a>00764     <span class="comment">/* Activate the synchronous signal handler which eventually will try to</span>
<a name="l00765"></a>00765 <span class="comment">       properly shutdown drive and library on aborting events. */</span>
<a name="l00766"></a>00766     <a class="code" href="libburn_8h.html#a47b6e05ca3f53ca00f0ef4103eb5cd18" title="Control built-in signal handling.">burn_set_signal_handling</a>(<span class="stringliteral">&quot;libburner : &quot;</span>, NULL, 0x0);
<a name="l00767"></a>00767 <span class="comment"></span>
<a name="l00768"></a>00768 <span class="comment">    /** Note: driveno might change its value in this call */</span>
<a name="l00769"></a>00769     ret = <a class="code" href="libburner_8c.html#ab485e1b9ba9572fb7596ffa6d6ff67c7" title="You need to aquire a drive before burning.">libburner_aquire_drive</a>(<a class="code" href="libburner_8c.html#adbe410a004b2aefa8868608beb2e5df1" title="The setup parameters of libburner.">drive_adr</a>, &amp;<a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a>);
<a name="l00770"></a>00770     <span class="keywordflow">if</span> (ret&lt;=0) {
<a name="l00771"></a>00771         fprintf(stderr,<span class="stringliteral">&quot;\nFATAL: Failed to aquire drive.\n&quot;</span>);
<a name="l00772"></a>00772         { ret = 34; <span class="keywordflow">goto</span> finish_libburn; }
<a name="l00773"></a>00773     }
<a name="l00774"></a>00774     <span class="keywordflow">if</span> (ret == 2)
<a name="l00775"></a>00775         { ret = 0; <span class="keywordflow">goto</span> release_drive; }
<a name="l00776"></a>00776     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aec8a1ef7e11653bc93fe1d5b2c63c9d3">do_blank</a>) {
<a name="l00777"></a>00777         <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aec8a1ef7e11653bc93fe1d5b2c63c9d3">do_blank</a> &gt; 100)
<a name="l00778"></a>00778             ret = <a class="code" href="libburner_8c.html#a42f03141c04bc55410fdc8e93c4f0143" title="Formats unformatted DVD-RW to profile 0013h &quot;Restricted Overwrite&quot; which needs no blanking for re-use...">libburner_format</a>(drive_list[<a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a>].drive);
<a name="l00779"></a>00779         <span class="keywordflow">else</span>
<a name="l00780"></a>00780             ret = <a class="code" href="libburner_8c.html#a0d4b7dff006b3f1f2aac1acc48ba99df" title="Makes a previously used CD-RW or unformatted DVD-RW ready for thorough re-usal.">libburner_blank_disc</a>(drive_list[<a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a>].drive,
<a name="l00781"></a>00781                             <a class="code" href="libburner_8c.html#aec8a1ef7e11653bc93fe1d5b2c63c9d3">do_blank</a> == 1);
<a name="l00782"></a>00782         <span class="keywordflow">if</span> (ret&lt;=0)
<a name="l00783"></a>00783             { ret = 36; <span class="keywordflow">goto</span> release_drive; }
<a name="l00784"></a>00784     }
<a name="l00785"></a>00785     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">source_adr_count</a> &gt; 0) {
<a name="l00786"></a>00786         ret = <a class="code" href="libburner_8c.html#af9c2fc57ed6d8505b22d377daef4914b" title="Brings preformatted track images (ISO 9660, audio, ...) onto media.">libburner_payload</a>(drive_list[<a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a>].drive,
<a name="l00787"></a>00787                 <a class="code" href="libburner_8c.html#a20401aa73b1b1c04c3faddfd1647f302">source_adr</a>, <a class="code" href="libburner_8c.html#a896ce0b6e3a7f1c4aa381a351f45106b">source_adr_count</a>,
<a name="l00788"></a>00788                 <a class="code" href="libburner_8c.html#a8e824cc51e6e6cfc91ac1df7830a70ed">do_multi</a>, <a class="code" href="libburner_8c.html#a0987fdf0d2c39990a6de69c649f4d470">simulate_burn</a>, <a class="code" href="libburner_8c.html#acdd017f7636e63e635f981e11aca9a22">all_tracks_type</a>);
<a name="l00789"></a>00789         <span class="keywordflow">if</span> (ret&lt;=0)
<a name="l00790"></a>00790             { ret = 38; <span class="keywordflow">goto</span> release_drive; }
<a name="l00791"></a>00791     }
<a name="l00792"></a>00792     ret = 0;
<a name="l00793"></a>00793 release_drive:;
<a name="l00794"></a>00794     <span class="keywordflow">if</span> (<a class="code" href="libburner_8c.html#aaee536e445f55d19bfeb431850ec90e4" title="This variable indicates wether the drive is grabbed and must be finally released.">drive_is_grabbed</a>)
<a name="l00795"></a>00795         <a class="code" href="libburn_8h.html#a765bba03b9f40c07f159ff9ef7db0e09" title="Release a drive.">burn_drive_release</a>(drive_list[<a class="code" href="libburner_8c.html#ae62e41d8013871fadd6094bf505bf0e3">driveno</a>].drive, 0);
<a name="l00796"></a>00796 
<a name="l00797"></a>00797 finish_libburn:;
<a name="l00798"></a>00798     <span class="keywordflow">if</span> (<a class="code" href="libburn_8h.html#a98a208e78cc9126a07d1bceea775f4db">burn_is_aborting</a>(0) &gt; 0) {
<a name="l00799"></a>00799         <a class="code" href="libburn_8h.html#aa07803603e8be01157ab6a667c5b5a6e" title="Abort any running drive operation and eventually call burn_finish().">burn_abort</a>(4400, <a class="code" href="libburn_8h.html#ad0fd9f069a3f4beb999942b2ec9e82a9" title="A pacifier function suitable for burn_abort.">burn_abort_pacifier</a>, <span class="stringliteral">&quot;libburner : &quot;</span>);
<a name="l00800"></a>00800         fprintf(stderr,<span class="stringliteral">&quot;\nlibburner run aborted\n&quot;</span>);
<a name="l00801"></a>00801         exit(1);
<a name="l00802"></a>00802     } 
<a name="l00803"></a>00803     <span class="comment">/* This app does not bother to know about exact scan state. </span>
<a name="l00804"></a>00804 <span class="comment">       Better to accept a memory leak here. We are done anyway. */</span>
<a name="l00805"></a>00805     <span class="comment">/* burn_drive_info_free(drive_list); */</span>
<a name="l00806"></a>00806     <a class="code" href="libburn_8h.html#ab9b933537517c9fda9758a9f2b4af337" title="Shutdown the library.">burn_finish</a>();
<a name="l00807"></a>00807     exit(ret);
<a name="l00808"></a>00808 }
<a name="l00809"></a>00809 
<a name="l00810"></a>00810 
<a name="l00811"></a>00811 <span class="comment">/*  License and copyright aspects:</span>
<a name="l00812"></a>00812 <span class="comment"></span>
<a name="l00813"></a>00813 <span class="comment">This all is provided under GPL.</span>
<a name="l00814"></a>00814 <span class="comment">Read. Try. Think. Play. Write yourself some code. Be free of my copyright.</span>
<a name="l00815"></a>00815 <span class="comment"></span>
<a name="l00816"></a>00816 <span class="comment">Be also invited to study the code of cdrskin/cdrskin.c et al.</span>
<a name="l00817"></a>00817 <span class="comment"></span>
<a name="l00818"></a>00818 <span class="comment">History:</span>
<a name="l00819"></a>00819 <span class="comment">libburner is a compilation of my own contributions to test/burniso.c and</span>
<a name="l00820"></a>00820 <span class="comment">fresh code which replaced the remaining parts under copyright of</span>
<a name="l00821"></a>00821 <span class="comment">Derek Foreman.</span>
<a name="l00822"></a>00822 <span class="comment">My respect and my thanks to Derek for providing me a start back in 2005.</span>
<a name="l00823"></a>00823 <span class="comment"></span>
<a name="l00824"></a>00824 <span class="comment">*/</span>
<a name="l00825"></a>00825 
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Sun May 13 2012 for libburn by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>