home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Utilities / mkisofs-1.11-MIHS / cdwrite.c.diff < prev    next >
Encoding:
Text File  |  1997-04-09  |  9.2 KB  |  367 lines

  1. #    $Id: cdwrite.c.diff,v 1.2 1997/02/23 15:46:59 eric Rel $    
  2. *** cdwrite.c.~1~    Mon Nov 20 20:58:51 1995
  3. --- cdwrite.c    Fri Dec 13 11:03:21 1996
  4. ***************
  5. *** 27,32 ****
  6. --- 27,34 ----
  7.   #endif
  8.   const char *default_dev = DEFAULT_DEV;
  9.   
  10. + #define MULTI_SESS    1
  11.   #include <stdio.h>
  12.   #include <stdlib.h>
  13.   #include <stdarg.h>
  14. ***************
  15. *** 43,53 ****
  16. --- 45,62 ----
  17.   #include <limits.h>
  18.   
  19.   #include <linux/version.h>
  20. + #include <linux/cdrom.h>
  21.   #ifndef LINUX_VERSION_CODE    /* Very old kernel? */
  22.   #define LINUX_VERSION_CODE 0
  23.   #endif
  24.   #if LINUX_VERSION_CODE >= 0x01031a /* <linux/scsi.h> introduced in 1.3.26 */
  25. + #if LINUX_VERSION_CODE >= 0x020000 /* <scsi/scsi.h> introduced somewhere. */
  26. + /* Need to fine tune the ifdef so we get the transition point right. */
  27. + #include <scsi/scsi.h>
  28. + #else
  29.   #include <linux/scsi.h>
  30. + #endif
  31.   #else
  32.   #define __KERNEL__
  33.   #include <linux/fs.h>
  34. ***************
  35. *** 124,129 ****
  36. --- 133,139 ----
  37.     unsigned char bytes[100];
  38.   };
  39.   
  40. + #define FIRST_WRITABLE_ADDRESS    0xE2
  41.   #define RESERVE_TRACK    0xE4
  42.   #define WRITE_TRACK    0xE6
  43.   #define LOAD_UNLOAD    0xE7    /* Philips/IMS/Kodak, HP */
  44. ***************
  45. *** 131,136 ****
  46. --- 141,154 ----
  47.   #define FIXATION    0xE9    /* Write table of contents */
  48.   #define RECOVER        0xEC
  49.   
  50. + /*
  51. +  * Bitmasks for word 8 of the fixate command.
  52. +  */
  53. + #define FIXATE_ONP    0x8
  54. + #define FIXATE_TOC_DA    0x0
  55. + #define FIXATE_TOC_ROM    0x1
  56. + #define FIXATE_TOC_XA1    0x2
  57. + #define FIXATE_TOC_XA2    0x3
  58.   /* Forward declarations */
  59.   
  60.   int
  61. ***************
  62. *** 220,233 ****
  63.   }
  64.   
  65.   int
  66. ! write_data_track (int fd, int *reply_len, struct sg_reply *rep) {
  67.      *reply_len = sizeof(struct sg_reply);
  68.      return send_request (fd, "write_data_track", reply_len, rep, 10,
  69.               WRITE_TRACK,    /* 0 */
  70.               0,        /* 1 */
  71.               0,0,0,        /* 2..4 */
  72.               0,            /* 5: track number (0=new) */
  73. !             1,        /* 6: data track, mode 1 */
  74.               0,0,0        /* 7..9 */);
  75.   }
  76.   
  77. --- 238,273 ----
  78.   }
  79.   
  80.   int
  81. ! write_data_track (int fd, int *reply_len, struct sg_reply *rep,
  82. !           int multi_sess) 
  83. ! {
  84. !   int    track_mode;
  85. !   /*
  86. !    * For non-multi-session discs, mode 1 is good enough.  If we want
  87. !    * multi-session, we really want mode 2 instead.
  88. !    */
  89. !   if( multi_sess )
  90. !     {
  91. !       track_mode = 2;
  92. !     }
  93. !   else
  94. !     {
  95. !       track_mode = 1;
  96. !     }
  97.      *reply_len = sizeof(struct sg_reply);
  98. +    /*
  99. +     * Mode 2 is required for multi-session to work properly.
  100. +     * Mode 1 works for single-session discs.
  101. +     */
  102.      return send_request (fd, "write_data_track", reply_len, rep, 10,
  103.               WRITE_TRACK,    /* 0 */
  104.               0,        /* 1 */
  105.               0,0,0,        /* 2..4 */
  106.               0,            /* 5: track number (0=new) */
  107. !             track_mode,    /* 6: data track, mode 1/2 */
  108.               0,0,0        /* 7..9 */);
  109.   }
  110.   
  111. ***************
  112. *** 557,562 ****
  113. --- 597,649 ----
  114.   }
  115.   
  116.   int
  117. + read_tochdr (int fd, int *reply_len, struct sg_reply *rep) {
  118. +   
  119. +   *reply_len = sizeof( struct sg_reply );
  120. +   return send_request (fd, "read_tochdr", reply_len, rep, 10,
  121. +                READ_TOC,    /* 0 */
  122. +                0,        /* 1 */
  123. +                0,0,        /* 2..3 */
  124. +                0,        /* 4 */
  125. +                0,        /* 5 */
  126. +                0,        /* 6 */
  127. +                0,        /* 7 */
  128. +                12,        /* 8 */
  129. +                0        /* 9 */);
  130. + }
  131. + int
  132. + read_tocentry (int fd, int track, int *reply_len, struct sg_reply *rep) {
  133. +    *reply_len = sizeof( struct sg_reply );
  134. +    return send_request (fd, "read_tocentry", reply_len, rep, 10,
  135. +             READ_TOC,    /* 0 */
  136. +             0,        /* 1 */
  137. +             0,0,        /* 2..3 */
  138. +             0,        /* 4 */
  139. +             0,        /* 5 */
  140. +             track,        /* 6 */
  141. +             0,        /* 7 */
  142. +             12,        /* 8 */
  143. +             0        /* 9 */);
  144. + }
  145. + int
  146. + first_writable_address (int fd, int *reply_len, struct sg_reply *rep) {
  147. +   
  148. +   *reply_len = sizeof( struct sg_reply );
  149. +   return send_request (fd, "read_tochdr", reply_len, rep, 10,
  150. +                FIRST_WRITABLE_ADDRESS,    /* 0 */
  151. +                0,        /* 1 */
  152. +                0,1,        /* 2..3 */
  153. +                0,        /* 4 */
  154. +                0,        /* 5 */
  155. +                0,        /* 6 */
  156. +                0,        /* 7 */
  157. +                12,        /* 8 */
  158. +                0        /* 9 */);
  159. + }
  160. + int
  161.   synchronize_cache (int fd, int *reply_len, struct sg_reply *rep) {
  162.      *reply_len = sizeof( struct sg_reply );
  163.      return send_request (fd, "synchronize_cache", reply_len, rep, 10,
  164. ***************
  165. *** 577,588 ****
  166.   }
  167.   
  168.   int
  169. ! fixation (int fd, int *reply_len, struct sg_reply *rep, int cdrom) {
  170.      *reply_len = sizeof( struct sg_reply );
  171.      return send_request (fd, "fixation", reply_len, rep, 10,
  172.               FIXATION,       /* 0 */
  173.               0,0,0,0,0,0,0,  /* 1..7 */
  174. !             cdrom ? 1 : 0,    /* 8: TOC type */
  175.               0        /* 9 */);
  176.   }
  177.   
  178. --- 664,706 ----
  179.   }
  180.   
  181.   int
  182. ! fixation (int fd, int *reply_len, struct sg_reply *rep, int cdrom,
  183. !       int multi_session) 
  184. ! {
  185. !    int    toc_type;
  186.      *reply_len = sizeof( struct sg_reply );
  187. +    /*
  188. +     * Fixation type 0 means audio.
  189. +     *           type 1 means vanilla non-XA cdrom.
  190. +     *           type 2 means XA with first track in mode 1.
  191. +     *           type 3 means XA with first track in mode 2.
  192. +     */
  193. +    if( !cdrom )
  194. +      {
  195. +        /*
  196. +     * Audio disc.
  197. +     */
  198. +        toc_type = FIXATE_TOC_DA;
  199. +      }
  200. +    else if (multi_session)
  201. +      {
  202. +        toc_type = FIXATE_ONP | FIXATE_TOC_XA2;
  203. +      }
  204. +    else
  205. +      {
  206. +        /*
  207. +     * For a single-session disc, we are not opening a new
  208. +     * program area, and we can write a vanilla non-XA track.
  209. +     */
  210. +        toc_type = FIXATE_TOC_ROM;
  211. +      }
  212.      return send_request (fd, "fixation", reply_len, rep, 10,
  213.               FIXATION,       /* 0 */
  214.               0,0,0,0,0,0,0,  /* 1..7 */
  215. !             toc_type,    /* 8: TOC type */
  216.               0        /* 9 */);
  217.   }
  218.   
  219. ***************
  220. *** 912,917 ****
  221. --- 1030,1036 ----
  222.     {"--eject", 'e'},
  223.     {"--device", 'D'},
  224.     {"--philips", 1001},
  225. +   {"--multi", 'm'},
  226.     {"--ims", 1001},
  227.     {"--kodak", 1001},
  228.     {"--yamaha", 1002},
  229. ***************
  230. *** 943,948 ****
  231. --- 1062,1068 ----
  232.      int tracks = 0;
  233.      int do_eject = 0;
  234.      int cdrom = 0;
  235. +    int do_multi_info = 0;
  236.      struct track_info_t track_info[MAX_TRACKS];
  237.      struct track_info_t trackopt;
  238.      const char *cd_writer = default_dev;
  239. ***************
  240. *** 1013,1018 ****
  241. --- 1133,1144 ----
  242.          
  243.              switch(optchar)
  244.            {
  245. +          case 'm':
  246. +            /*
  247. +             * Enable information gathering mode for cdwrite.
  248. +             */
  249. +            do_multi_info = 1;
  250. +            break;
  251.            case 'b':    /* -b, --bytes */
  252.              trackopt.bytes = atoi(argv[++i]);
  253.              break;
  254. ***************
  255. *** 1119,1125 ****
  256.      if ( verbose )
  257.        printf("cdwrite %s\n", version);
  258.   
  259. !    if ( !tracks && !do_eject )
  260.        {
  261.          /* If no tracks specified, only auxilliary actions */
  262.   
  263. --- 1245,1251 ----
  264.      if ( verbose )
  265.        printf("cdwrite %s\n", version);
  266.   
  267. !    if ( !tracks && !do_eject && !do_multi_info )
  268.        {
  269.          /* If no tracks specified, only auxilliary actions */
  270.   
  271. ***************
  272. *** 1238,1243 ****
  273. --- 1364,1403 ----
  274.             Manufacturer, Model, Revision, type_name[cdwriter_type]);
  275.        }
  276.      
  277. +    if( do_multi_info )
  278. +      {
  279. +        int    last_track;
  280. +        int    vol_start;
  281. +        int    next_writable_address = 0;
  282. +        /*
  283. +     * If the user simply wants an information gathering to take
  284. +     * place so that multi-session works, then do it.
  285. +     */
  286. +        read_tochdr(fd, &reply_len, &reply);
  287. +        last_track = reply.bytes[3];
  288. +        read_tocentry(fd, last_track, &reply_len, &reply);
  289. +        vol_start = (reply.bytes[8] << 24) 
  290. +      | (reply.bytes[9] << 16) 
  291. +      | (reply.bytes[10] << 8) 
  292. +      | reply.bytes[11];  
  293. +        first_writable_address(fd, &reply_len, &reply);
  294. +        next_writable_address = (reply.bytes[1] << 24) 
  295. +      | (reply.bytes[2] << 16) 
  296. +      | (reply.bytes[3] << 8) 
  297. +      | reply.bytes[4];  
  298. +        
  299. +        /*
  300. +     * These are the two numbers that mkisofs wants to see.  For now,
  301. +     * it is just hacked together so that people can use it, but
  302. +     * in the future the integration will be tighter and cleaner.
  303. +     */
  304. +        printf("%d,%d",vol_start, next_writable_address);
  305. +        exit(0);
  306. +      }
  307.      /* Do mode-dependent adjustments here */
  308.   
  309.      if ( speed_factor == 0 && cdwriter_type != type_hp )
  310. ***************
  311. *** 1275,1281 ****
  312.          if ( track_info[i].audio )
  313.            write_audio_track (fd, &reply_len, &reply, track_info[i].preemp);
  314.          else
  315. !          write_data_track (fd, &reply_len, &reply);
  316.          
  317.          pipe_to_cd (&track_info[i], fd, &reply_len, &reply);
  318.          synchronize_cache (fd, &reply_len, &reply);
  319. --- 1435,1441 ----
  320.          if ( track_info[i].audio )
  321.            write_audio_track (fd, &reply_len, &reply, track_info[i].preemp);
  322.          else
  323. !          write_data_track (fd, &reply_len, &reply, MULTI_SESS);
  324.          
  325.          pipe_to_cd (&track_info[i], fd, &reply_len, &reply);
  326.          synchronize_cache (fd, &reply_len, &reply);
  327. ***************
  328. *** 1283,1290 ****
  329.   
  330.          if ( verbose )
  331.        printf("Fixating...\n");
  332. !        fixation(fd, &reply_len, &reply, cdrom);
  333. !        
  334.          if (cdwriter_type != type_yamaha)
  335.        {
  336.          /* Possibly unneeded, but doesn't hurt */
  337. --- 1443,1456 ----
  338.   
  339.          if ( verbose )
  340.        printf("Fixating...\n");
  341. !        /*
  342. !     * The last parameter must be non-zero if we *ever* want to write
  343. !     * another session on this disc.  If we use a 0 here, it is
  344. !     * effectively like breaking off a write-protect tab on the disc.
  345. !     */
  346. !        fixation(fd, &reply_len, &reply, cdrom, MULTI_SESS);
  347.          if (cdwriter_type != type_yamaha)
  348.        {
  349.          /* Possibly unneeded, but doesn't hurt */
  350.