| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | #include "../libburn/libburn.h" |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | #include <stdio.h> |
|---|
| 71 | #include <ctype.h> |
|---|
| 72 | #include <sys/types.h> |
|---|
| 73 | #include <unistd.h> |
|---|
| 74 | #include <string.h> |
|---|
| 75 | #include <stdlib.h> |
|---|
| 76 | #include <time.h> |
|---|
| 77 | #include <errno.h> |
|---|
| 78 | #include <sys/stat.h> |
|---|
| 79 | #include <fcntl.h> |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | static struct burn_drive_info *drive_list; |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | static unsigned int drive_count; |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | static int drive_is_grabbed = 0; |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | static int current_profile= -1; |
|---|
| 101 | static char current_profile_name[80]= {""}; |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | int libburner_aquire_by_adr(char *drive_adr); |
|---|
| 107 | int libburner_aquire_by_driveno(int *drive_no); |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | int libburner_aquire_drive(char *drive_adr, int *driveno) |
|---|
| 124 | { |
|---|
| 125 | int ret; |
|---|
| 126 | |
|---|
| 127 | if(drive_adr != NULL && drive_adr[0] != 0) |
|---|
| 128 | ret = libburner_aquire_by_adr(drive_adr); |
|---|
| 129 | else |
|---|
| 130 | ret = libburner_aquire_by_driveno(driveno); |
|---|
| 131 | if (ret <= 0 || *driveno <= 0) |
|---|
| 132 | return ret; |
|---|
| 133 | burn_disc_get_profile(drive_list[0].drive, ¤t_profile, |
|---|
| 134 | current_profile_name); |
|---|
| 135 | if (current_profile_name[0]) |
|---|
| 136 | printf("Detected media type: %s\n", current_profile_name); |
|---|
| 137 | return 1; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | int libburner_aquire_by_adr(char *drive_adr) |
|---|
| 146 | { |
|---|
| 147 | int ret; |
|---|
| 148 | char libburn_drive_adr[BURN_DRIVE_ADR_LEN]; |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | if (strncmp(drive_adr, "stdio:/dev/fd/", 14) == 0 || |
|---|
| 152 | strcmp(drive_adr, "stdio:-") == 0) { |
|---|
| 153 | fprintf(stderr, "Will not work with pseudo-drive '%s'\n", |
|---|
| 154 | drive_adr); |
|---|
| 155 | return 0; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | ret = burn_drive_convert_fs_adr(drive_adr, libburn_drive_adr); |
|---|
| 160 | if (ret<=0) { |
|---|
| 161 | fprintf(stderr, "Address does not lead to a CD burner: '%s'\n", |
|---|
| 162 | drive_adr); |
|---|
| 163 | return 0; |
|---|
| 164 | } |
|---|
| 165 | fprintf(stderr,"Aquiring drive '%s' ...\n", libburn_drive_adr); |
|---|
| 166 | ret = burn_drive_scan_and_grab(&drive_list, libburn_drive_adr, 1); |
|---|
| 167 | if (ret <= 0) { |
|---|
| 168 | fprintf(stderr,"FAILURE with persistent drive address '%s'\n", |
|---|
| 169 | libburn_drive_adr); |
|---|
| 170 | } else { |
|---|
| 171 | fprintf(stderr,"Done\n"); |
|---|
| 172 | drive_is_grabbed = 1; |
|---|
| 173 | } |
|---|
| 174 | return ret; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | int libburner_aquire_by_driveno(int *driveno) |
|---|
| 191 | { |
|---|
| 192 | char adr[BURN_DRIVE_ADR_LEN]; |
|---|
| 193 | int ret, i; |
|---|
| 194 | |
|---|
| 195 | printf("Beginning to scan for devices ...\n"); |
|---|
| 196 | while (!burn_drive_scan(&drive_list, &drive_count)) |
|---|
| 197 | usleep(100002); |
|---|
| 198 | if (drive_count <= 0 && *driveno >= 0) { |
|---|
| 199 | printf("FAILED (no drives found)\n"); |
|---|
| 200 | return 0; |
|---|
| 201 | } |
|---|
| 202 | printf("Done\n"); |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | printf("\nOverview of accessible drives (%d found) :\n", |
|---|
| 219 | drive_count); |
|---|
| 220 | printf("-----------------------------------------------------------------------------\n"); |
|---|
| 221 | for (i = 0; i < drive_count; i++) { |
|---|
| 222 | if (burn_drive_get_adr(&(drive_list[i]), adr) <=0) |
|---|
| 223 | strcpy(adr, "-get_adr_failed-"); |
|---|
| 224 | printf("%d --drive '%s' : '%s' '%s'\n", |
|---|
| 225 | i,adr,drive_list[i].vendor,drive_list[i].product); |
|---|
| 226 | } |
|---|
| 227 | printf("-----------------------------------------------------------------------------\n\n"); |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | if (*driveno < 0) { |
|---|
| 255 | printf("Pseudo-drive \"-\" given : bus scanning done.\n"); |
|---|
| 256 | return 2; |
|---|
| 257 | } |
|---|
| 258 | if (drive_count <= *driveno) { |
|---|
| 259 | fprintf(stderr, |
|---|
| 260 | "Found only %d drives. Number %d not available.\n", |
|---|
| 261 | drive_count, *driveno); |
|---|
| 262 | return 0; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | for (i = 0; i < drive_count; i++) { |
|---|
| 267 | if (i == *driveno) |
|---|
| 268 | continue; |
|---|
| 269 | ret = burn_drive_info_forget(&(drive_list[i]),0); |
|---|
| 270 | if (ret != 1) |
|---|
| 271 | fprintf(stderr, "Cannot drop drive %d. Please report \"ret=%d\" to libburn-hackers@pykix.org\n", |
|---|
| 272 | i, ret); |
|---|
| 273 | else |
|---|
| 274 | printf("Dropped unwanted drive %d\n",i); |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | ret= burn_drive_grab(drive_list[*driveno].drive, 1); |
|---|
| 278 | if (ret != 1) |
|---|
| 279 | return 0; |
|---|
| 280 | drive_is_grabbed = 1; |
|---|
| 281 | return 1; |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | int libburner_blank_disc(struct burn_drive *drive, int blank_fast) |
|---|
| 294 | { |
|---|
| 295 | enum burn_disc_status disc_state; |
|---|
| 296 | struct burn_progress p; |
|---|
| 297 | double percent = 1.0; |
|---|
| 298 | |
|---|
| 299 | disc_state = burn_disc_get_status(drive); |
|---|
| 300 | printf( |
|---|
| 301 | "Drive media status: %d (see libburn/libburn.h BURN_DISC_*)\n", |
|---|
| 302 | disc_state); |
|---|
| 303 | if (current_profile == 0x13) { |
|---|
| 304 | ; |
|---|
| 305 | } else if (disc_state == BURN_DISC_BLANK) { |
|---|
| 306 | fprintf(stderr, |
|---|
| 307 | "IDLE: Blank media detected. Will leave it untouched\n"); |
|---|
| 308 | return 2; |
|---|
| 309 | } else if (disc_state == BURN_DISC_FULL || |
|---|
| 310 | disc_state == BURN_DISC_APPENDABLE) { |
|---|
| 311 | ; |
|---|
| 312 | } else if (disc_state == BURN_DISC_EMPTY) { |
|---|
| 313 | fprintf(stderr,"FATAL: No media detected in drive\n"); |
|---|
| 314 | return 0; |
|---|
| 315 | } else { |
|---|
| 316 | fprintf(stderr, |
|---|
| 317 | "FATAL: Unsuitable drive and media state\n"); |
|---|
| 318 | return 0; |
|---|
| 319 | } |
|---|
| 320 | if(!burn_disc_erasable(drive)) { |
|---|
| 321 | fprintf(stderr, |
|---|
| 322 | "FATAL : Media is not of erasable type\n"); |
|---|
| 323 | return 0; |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | burn_set_signal_handling("libburner : ", NULL, 0x30); |
|---|
| 327 | |
|---|
| 328 | printf("Beginning to %s-blank media.\n", (blank_fast?"fast":"full")); |
|---|
| 329 | burn_disc_erase(drive, blank_fast); |
|---|
| 330 | |
|---|
| 331 | sleep(1); |
|---|
| 332 | while (burn_drive_get_status(drive, &p) != BURN_DRIVE_IDLE) { |
|---|
| 333 | if(p.sectors>0 && p.sector>=0) |
|---|
| 334 | percent = 1.0 + ((double) p.sector+1.0) |
|---|
| 335 | / ((double) p.sectors) * 98.0; |
|---|
| 336 | printf("Blanking ( %.1f%% done )\n", percent); |
|---|
| 337 | sleep(1); |
|---|
| 338 | } |
|---|
| 339 | if (burn_is_aborting(0) > 0) |
|---|
| 340 | return -1; |
|---|
| 341 | |
|---|
| 342 | burn_set_signal_handling("libburner : ", NULL, 0x0); |
|---|
| 343 | printf("Done\n"); |
|---|
| 344 | return 1; |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | |
|---|
| 357 | |
|---|
| 358 | |
|---|
| 359 | |
|---|
| 360 | int libburner_format(struct burn_drive *drive) |
|---|
| 361 | { |
|---|
| 362 | struct burn_progress p; |
|---|
| 363 | double percent = 1.0; |
|---|
| 364 | int ret, status, num_formats, format_flag= 0; |
|---|
| 365 | off_t size = 0; |
|---|
| 366 | unsigned dummy; |
|---|
| 367 | enum burn_disc_status disc_state; |
|---|
| 368 | |
|---|
| 369 | if (current_profile == 0x13) { |
|---|
| 370 | fprintf(stderr, "IDLE: DVD-RW media is already formatted\n"); |
|---|
| 371 | return 2; |
|---|
| 372 | } else if (current_profile == 0x41 || current_profile == 0x43) { |
|---|
| 373 | disc_state = burn_disc_get_status(drive); |
|---|
| 374 | if (disc_state != BURN_DISC_BLANK && current_profile == 0x41) { |
|---|
| 375 | fprintf(stderr, |
|---|
| 376 | "FATAL: BD-R is not blank. Cannot format.\n"); |
|---|
| 377 | return 0; |
|---|
| 378 | } |
|---|
| 379 | ret = burn_disc_get_formats(drive, &status, &size, &dummy, |
|---|
| 380 | &num_formats); |
|---|
| 381 | if (ret > 0 && status != BURN_FORMAT_IS_UNFORMATTED) { |
|---|
| 382 | fprintf(stderr, |
|---|
| 383 | "IDLE: BD media is already formatted\n"); |
|---|
| 384 | return 2; |
|---|
| 385 | } |
|---|
| 386 | size = 0; |
|---|
| 387 | format_flag = 3<<1; |
|---|
| 388 | } else if (current_profile == 0x14) { |
|---|
| 389 | size = 128 * 1024 * 1024; |
|---|
| 390 | format_flag = 1; |
|---|
| 391 | } else { |
|---|
| 392 | fprintf(stderr, "FATAL: Can only format DVD-RW or BD\n"); |
|---|
| 393 | return 0; |
|---|
| 394 | } |
|---|
| 395 | burn_set_signal_handling("libburner : ", NULL, 0x30); |
|---|
| 396 | |
|---|
| 397 | printf("Beginning to format media.\n"); |
|---|
| 398 | burn_disc_format(drive, size, format_flag); |
|---|
| 399 | |
|---|
| 400 | sleep(1); |
|---|
| 401 | while (burn_drive_get_status(drive, &p) != BURN_DRIVE_IDLE) { |
|---|
| 402 | if(p.sectors>0 && p.sector>=0) |
|---|
| 403 | percent = 1.0 + ((double) p.sector+1.0) |
|---|
| 404 | / ((double) p.sectors) * 98.0; |
|---|
| 405 | printf("Formatting ( %.1f%% done )\n", percent); |
|---|
| 406 | sleep(1); |
|---|
| 407 | } |
|---|
| 408 | if (burn_is_aborting(0) > 0) |
|---|
| 409 | return -1; |
|---|
| 410 | burn_set_signal_handling("libburner : ", NULL, 0x0); |
|---|
| 411 | burn_disc_get_profile(drive_list[0].drive, ¤t_profile, |
|---|
| 412 | current_profile_name); |
|---|
| 413 | if (current_profile == 0x14 || current_profile == 0x13) |
|---|
| 414 | printf("Media type now: %4.4xh \"%s\"\n", |
|---|
| 415 | current_profile, current_profile_name); |
|---|
| 416 | if (current_profile == 0x14) { |
|---|
| 417 | fprintf(stderr, |
|---|
| 418 | "FATAL: Failed to change media profile to desired value\n"); |
|---|
| 419 | return 0; |
|---|
| 420 | } |
|---|
| 421 | return 1; |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | |
|---|
| 440 | int libburner_payload(struct burn_drive *drive, |
|---|
| 441 | char source_adr[][4096], int source_adr_count, |
|---|
| 442 | int multi, int simulate_burn, int all_tracks_type) |
|---|
| 443 | { |
|---|
| 444 | struct burn_source *data_src, *fifo_src[99]; |
|---|
| 445 | struct burn_disc *target_disc; |
|---|
| 446 | struct burn_session *session; |
|---|
| 447 | struct burn_write_opts *burn_options; |
|---|
| 448 | enum burn_disc_status disc_state; |
|---|
| 449 | struct burn_track *track, *tracklist[99]; |
|---|
| 450 | struct burn_progress progress; |
|---|
| 451 | time_t start_time; |
|---|
| 452 | int last_sector = 0, padding = 0, trackno, unpredicted_size = 0, fd; |
|---|
| 453 | int fifo_chunksize = 2352, fifo_chunks = 1783; |
|---|
| 454 | off_t fixed_size; |
|---|
| 455 | char *adr, reasons[BURN_REASONS_LEN]; |
|---|
| 456 | struct stat stbuf; |
|---|
| 457 | |
|---|
| 458 | if (all_tracks_type != BURN_AUDIO) { |
|---|
| 459 | all_tracks_type = BURN_MODE1; |
|---|
| 460 | |
|---|
| 461 | padding = 300*1024; |
|---|
| 462 | fifo_chunksize = 2048; |
|---|
| 463 | fifo_chunks = 2048; |
|---|
| 464 | } |
|---|
| 465 | |
|---|
| 466 | target_disc = burn_disc_create(); |
|---|
| 467 | session = burn_session_create(); |
|---|
| 468 | burn_disc_add_session(target_disc, session, BURN_POS_END); |
|---|
| 469 | |
|---|
| 470 | for (trackno = 0 ; trackno < source_adr_count; trackno++) { |
|---|
| 471 | tracklist[trackno] = track = burn_track_create(); |
|---|
| 472 | burn_track_define_data(track, 0, padding, 1, all_tracks_type); |
|---|
| 473 | |
|---|
| 474 | |
|---|
| 475 | adr = source_adr[trackno]; |
|---|
| 476 | fixed_size = 0; |
|---|
| 477 | if (adr[0] == '-' && adr[1] == 0) { |
|---|
| 478 | fd = 0; |
|---|
| 479 | } else { |
|---|
| 480 | fd = open(adr, O_RDONLY); |
|---|
| 481 | if (fd>=0) |
|---|
| 482 | if (fstat(fd,&stbuf)!=-1) |
|---|
| 483 | if((stbuf.st_mode&S_IFMT)==S_IFREG) |
|---|
| 484 | fixed_size = stbuf.st_size; |
|---|
| 485 | } |
|---|
| 486 | if (fixed_size==0) |
|---|
| 487 | unpredicted_size = 1; |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | data_src = NULL; |
|---|
| 491 | if (fd>=0) |
|---|
| 492 | data_src = burn_fd_source_new(fd, -1, fixed_size); |
|---|
| 493 | if (data_src == NULL) { |
|---|
| 494 | fprintf(stderr, |
|---|
| 495 | "FATAL: Could not open data source '%s'.\n",adr); |
|---|
| 496 | if(errno!=0) |
|---|
| 497 | fprintf(stderr,"(Most recent system error: %s )\n", |
|---|
| 498 | strerror(errno)); |
|---|
| 499 | return 0; |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | fifo_src[trackno] = burn_fifo_source_new(data_src, |
|---|
| 503 | fifo_chunksize, fifo_chunks, 0); |
|---|
| 504 | if (fifo_src[trackno] == NULL) { |
|---|
| 505 | fprintf(stderr, |
|---|
| 506 | "FATAL: Could not create fifo object of 4 MB\n"); |
|---|
| 507 | return 0; |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | |
|---|
| 511 | if (burn_track_set_source(track, fifo_src[trackno]) |
|---|
| 512 | != BURN_SOURCE_OK) { |
|---|
| 513 | fprintf(stderr, |
|---|
| 514 | "FATAL: Cannot attach source object to track object\n"); |
|---|
| 515 | return 0; |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | burn_session_add_track(session, track, BURN_POS_END); |
|---|
| 519 | printf("Track %d : source is '%s'\n", trackno+1, adr); |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | burn_source_free(data_src); |
|---|
| 523 | |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | disc_state = burn_disc_get_status(drive); |
|---|
| 528 | if (disc_state != BURN_DISC_BLANK && |
|---|
| 529 | disc_state != BURN_DISC_APPENDABLE) { |
|---|
| 530 | if (disc_state == BURN_DISC_FULL) { |
|---|
| 531 | fprintf(stderr, "FATAL: Closed media with data detected. Need blank or appendable media.\n"); |
|---|
| 532 | if (burn_disc_erasable(drive)) |
|---|
| 533 | fprintf(stderr, "HINT: Try --blank_fast\n\n"); |
|---|
| 534 | } else if (disc_state == BURN_DISC_EMPTY) |
|---|
| 535 | fprintf(stderr,"FATAL: No media detected in drive\n"); |
|---|
| 536 | else |
|---|
| 537 | fprintf(stderr, |
|---|
| 538 | "FATAL: Cannot recognize state of drive and media\n"); |
|---|
| 539 | return 0; |
|---|
| 540 | } |
|---|
| 541 | |
|---|
| 542 | burn_options = burn_write_opts_new(drive); |
|---|
| 543 | burn_write_opts_set_perform_opc(burn_options, 0); |
|---|
| 544 | burn_write_opts_set_multi(burn_options, !!multi); |
|---|
| 545 | if(simulate_burn) |
|---|
| 546 | printf("\n*** Will TRY to SIMULATE burning ***\n\n"); |
|---|
| 547 | burn_write_opts_set_simulate(burn_options, simulate_burn); |
|---|
| 548 | burn_drive_set_speed(drive, 0, 0); |
|---|
| 549 | burn_write_opts_set_underrun_proof(burn_options, 1); |
|---|
| 550 | if (burn_write_opts_auto_write_type(burn_options, target_disc, |
|---|
| 551 | reasons, 0) == BURN_WRITE_NONE) { |
|---|
| 552 | fprintf(stderr, "FATAL: Failed to find a suitable write mode with this media.\n"); |
|---|
| 553 | fprintf(stderr, "Reasons given:\n%s\n", reasons); |
|---|
| 554 | return 0; |
|---|
| 555 | } |
|---|
| 556 | burn_set_signal_handling("libburner : ", NULL, 0x30); |
|---|
| 557 | |
|---|
| 558 | printf("Burning starts. With e.g. 4x media expect up to a minute of zero progress.\n"); |
|---|
| 559 | start_time = time(0); |
|---|
| 560 | burn_disc_write(burn_options, target_disc); |
|---|
| 561 | |
|---|
| 562 | burn_write_opts_free(burn_options); |
|---|
| 563 | while (burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING) |
|---|
| 564 | usleep(100002); |
|---|
| 565 | while (burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) { |
|---|
| 566 | if (progress.sectors <= 0 || |
|---|
| 567 | (progress.sector >= progress.sectors - 1 && |
|---|
| 568 | !unpredicted_size) || |
|---|
| 569 | (unpredicted_size && progress.sector == last_sector)) |
|---|
| 570 | printf( |
|---|
| 571 | "Thank you for being patient since %d seconds.", |
|---|
| 572 | (int) (time(0) - start_time)); |
|---|
| 573 | else if(unpredicted_size) |
|---|
| 574 | printf("Track %d : sector %d", progress.track+1, |
|---|
| 575 | progress.sector); |
|---|
| 576 | else |
|---|
| 577 | printf("Track %d : sector %d of %d",progress.track+1, |
|---|
| 578 | progress.sector, progress.sectors); |
|---|
| 579 | last_sector = progress.sector; |
|---|
| 580 | if (progress.track >= 0 && progress.track < source_adr_count) { |
|---|
| 581 | int size, free_bytes, ret; |
|---|
| 582 | char *status_text; |
|---|
| 583 | |
|---|
| 584 | ret = burn_fifo_inquire_status( |
|---|
| 585 | fifo_src[progress.track], &size, &free_bytes, |
|---|
| 586 | &status_text); |
|---|
| 587 | if (ret >= 0 ) |
|---|
| 588 | printf(" [fifo %s, %2d%% fill]", status_text, |
|---|
| 589 | (int) (100.0 - 100.0 * |
|---|
| 590 | ((double) free_bytes) / |
|---|
| 591 | (double) size)); |
|---|
| 592 | } |
|---|
| 593 | printf("\n"); |
|---|
| 594 | sleep(1); |
|---|
| 595 | } |
|---|
| 596 | printf("\n"); |
|---|
| 597 | |
|---|
| 598 | for (trackno = 0 ; trackno < source_adr_count; trackno++) { |
|---|
| 599 | burn_source_free(fifo_src[trackno]); |
|---|
| 600 | burn_track_free(tracklist[trackno]); |
|---|
| 601 | } |
|---|
| 602 | burn_session_free(session); |
|---|
| 603 | burn_disc_free(target_disc); |
|---|
| 604 | if (burn_is_aborting(0) > 0) |
|---|
| 605 | return -1; |
|---|
| 606 | if (multi && current_profile != 0x1a && current_profile != 0x13 && |
|---|
| 607 | current_profile != 0x12 && current_profile != 0x43) |
|---|
| 608 | |
|---|
| 609 | printf("NOTE: Media left appendable.\n"); |
|---|
| 610 | if (simulate_burn) |
|---|
| 611 | printf("\n*** Did TRY to SIMULATE burning ***\n\n"); |
|---|
| 612 | return 1; |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | static char drive_adr[BURN_DRIVE_ADR_LEN] = {""}; |
|---|
| 618 | static int driveno = 0; |
|---|
| 619 | static int do_blank = 0; |
|---|
| 620 | static char source_adr[99][4096]; |
|---|
| 621 | static int source_adr_count = 0; |
|---|
| 622 | static int do_multi = 0; |
|---|
| 623 | static int simulate_burn = 0; |
|---|
| 624 | static int all_tracks_type = BURN_MODE1; |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | int libburner_setup(int argc, char **argv) |
|---|
| 630 | { |
|---|
| 631 | int i, insuffient_parameters = 0, print_help = 0; |
|---|
| 632 | |
|---|
| 633 | for (i = 1; i < argc; ++i) { |
|---|
| 634 | if (!strcmp(argv[i], "--audio")) { |
|---|
| 635 | all_tracks_type = BURN_AUDIO; |
|---|
| 636 | |
|---|
| 637 | } else if (!strcmp(argv[i], "--blank_fast")) { |
|---|
| 638 | do_blank = 1; |
|---|
| 639 | |
|---|
| 640 | } else if (!strcmp(argv[i], "--blank_full")) { |
|---|
| 641 | do_blank = 2; |
|---|
| 642 | |
|---|
| 643 | } else if (!strcmp(argv[i], "--burn_for_real")) { |
|---|
| 644 | simulate_burn = 0; |
|---|
| 645 | |
|---|
| 646 | } else if (!strcmp(argv[i], "--drive")) { |
|---|
| 647 | ++i; |
|---|
| 648 | if (i >= argc) { |
|---|
| 649 | fprintf(stderr,"--drive requires an argument\n"); |
|---|
| 650 | return 1; |
|---|
| 651 | } else if (strcmp(argv[i], "-") == 0) { |
|---|
| 652 | drive_adr[0] = 0; |
|---|
| 653 | driveno = -1; |
|---|
| 654 | } else if (isdigit(argv[i][0])) { |
|---|
| 655 | drive_adr[0] = 0; |
|---|
| 656 | driveno = atoi(argv[i]); |
|---|
| 657 | } else { |
|---|
| 658 | if(strlen(argv[i]) >= BURN_DRIVE_ADR_LEN) { |
|---|
| 659 | fprintf(stderr,"--drive address too long (max. %d)\n", |
|---|
| 660 | BURN_DRIVE_ADR_LEN-1); |
|---|
| 661 | return 2; |
|---|
| 662 | } |
|---|
| 663 | strcpy(drive_adr, argv[i]); |
|---|
| 664 | } |
|---|
| 665 | } else if ((!strcmp(argv[i], "--format_overwrite")) || |
|---|
| 666 | (!strcmp(argv[i], "--format"))) { |
|---|
| 667 | do_blank = 101; |
|---|
| 668 | |
|---|
| 669 | } else if (!strcmp(argv[i], "--multi")) { |
|---|
| 670 | do_multi = 1; |
|---|
| 671 | |
|---|
| 672 | } else if (!strcmp(argv[i], "--stdin_size")) { |
|---|
| 673 | i++; |
|---|
| 674 | |
|---|
| 675 | } else if (!strcmp(argv[i], "--try_to_simulate")) { |
|---|
| 676 | simulate_burn = 1; |
|---|
| 677 | |
|---|
| 678 | } else if (!strcmp(argv[i], "--help")) { |
|---|
| 679 | print_help = 1; |
|---|
| 680 | |
|---|
| 681 | } else if (!strncmp(argv[i], "--",2)) { |
|---|
| 682 | fprintf(stderr, "Unidentified option: %s\n", argv[i]); |
|---|
| 683 | return 7; |
|---|
| 684 | } else { |
|---|
| 685 | if(strlen(argv[i]) >= 4096) { |
|---|
| 686 | fprintf(stderr, "Source address too long (max. %d)\n", 4096-1); |
|---|
| 687 | return 5; |
|---|
| 688 | } |
|---|
| 689 | if(source_adr_count >= 99) { |
|---|
| 690 | fprintf(stderr, "Too many tracks (max. 99)\n"); |
|---|
| 691 | return 6; |
|---|
| 692 | } |
|---|
| 693 | strcpy(source_adr[source_adr_count], argv[i]); |
|---|
| 694 | source_adr_count++; |
|---|
| 695 | } |
|---|
| 696 | } |
|---|
| 697 | insuffient_parameters = 1; |
|---|
| 698 | if (driveno < 0) |
|---|
| 699 | insuffient_parameters = 0; |
|---|
| 700 | if (source_adr_count > 0) |
|---|
| 701 | insuffient_parameters = 0; |
|---|
| 702 | if (do_blank) |
|---|
| 703 | insuffient_parameters = 0; |
|---|
| 704 | if (print_help || insuffient_parameters ) { |
|---|
| 705 | printf("Usage: %s\n", argv[0]); |
|---|
| 706 | printf(" [--drive <address>|<driveno>|\"-\"] [--audio]\n"); |
|---|
| 707 | printf(" [--blank_fast|--blank_full|--format] [--try_to_simulate]\n"); |
|---|
| 708 | printf(" [--multi] [<one or more imagefiles>|\"-\"]\n"); |
|---|
| 709 | printf("Examples\n"); |
|---|
| 710 | printf("A bus scan (needs rw-permissions to see a drive):\n"); |
|---|
| 711 | printf(" %s --drive -\n",argv[0]); |
|---|
| 712 | printf("Burn a file to drive chosen by number, leave appendable:\n"); |
|---|
| 713 | printf(" %s --drive 0 --multi my_image_file\n", argv[0]); |
|---|
| 714 | printf("Burn a file to drive chosen by persistent address, close:\n"); |
|---|
| 715 | printf(" %s --drive /dev/hdc my_image_file\n", argv[0]); |
|---|
| 716 | printf("Blank a used CD-RW (is combinable with burning in one run):\n"); |
|---|
| 717 | printf(" %s --drive /dev/hdc --blank_fast\n",argv[0]); |
|---|
| 718 | printf("Blank a used DVD-RW (is combinable with burning in one run):\n"); |
|---|
| 719 | printf(" %s --drive /dev/hdc --blank_full\n",argv[0]); |
|---|
| 720 | printf("Format a DVD-RW, BD-RE or BD-R:\n"); |
|---|
| 721 | printf(" %s --drive /dev/hdc --format\n", argv[0]); |
|---|
| 722 | printf("Burn two audio tracks (to CD only):\n"); |
|---|
| 723 | printf(" lame --decode -t /path/to/track1.mp3 track1.cd\n"); |
|---|
| 724 | printf(" test/dewav /path/to/track2.wav -o track2.cd\n"); |
|---|
| 725 | printf(" %s --drive /dev/hdc --audio track1.cd track2.cd\n", argv[0]); |
|---|
| 726 | printf("Burn a compressed afio archive on-the-fly:\n"); |
|---|
| 727 | printf(" ( cd my_directory ; find . -print | afio -oZ - ) | \\\n"); |
|---|
| 728 | printf(" %s --drive /dev/hdc -\n", argv[0]); |
|---|
| 729 | printf("To be read from *not mounted* media via: afio -tvZ /dev/hdc\n"); |
|---|
| 730 | if (insuffient_parameters) |
|---|
| 731 | return 6; |
|---|
| 732 | } |
|---|
| 733 | return 0; |
|---|
| 734 | } |
|---|
| 735 | |
|---|
| 736 | |
|---|
| 737 | int main(int argc, char **argv) |
|---|
| 738 | { |
|---|
| 739 | int ret; |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | if (sizeof(off_t) != 8) { |
|---|
| 743 | fprintf(stderr, |
|---|
| 744 | "\nFATAL: Compile time misconfiguration. off_t is not 64 bit.\n\n"); |
|---|
| 745 | exit(39); |
|---|
| 746 | } |
|---|
| 747 | |
|---|
| 748 | ret = libburner_setup(argc, argv); |
|---|
| 749 | if (ret) |
|---|
| 750 | exit(ret); |
|---|
| 751 | |
|---|
| 752 | printf("Initializing libburnia-project.org ...\n"); |
|---|
| 753 | if (burn_initialize()) |
|---|
| 754 | printf("Done\n"); |
|---|
| 755 | else { |
|---|
| 756 | printf("FAILED\n"); |
|---|
| 757 | fprintf(stderr,"\nFATAL: Failed to initialize.\n"); |
|---|
| 758 | exit(33); |
|---|
| 759 | } |
|---|
| 760 | |
|---|
| 761 | |
|---|
| 762 | burn_msgs_set_severities("NEVER", "SORRY", "libburner : "); |
|---|
| 763 | |
|---|
| 764 | |
|---|
| 765 | |
|---|
| 766 | burn_set_signal_handling("libburner : ", NULL, 0x0); |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | ret = libburner_aquire_drive(drive_adr, &driveno); |
|---|
| 770 | if (ret<=0) { |
|---|
| 771 | fprintf(stderr,"\nFATAL: Failed to aquire drive.\n"); |
|---|
| 772 | { ret = 34; goto finish_libburn; } |
|---|
| 773 | } |
|---|
| 774 | if (ret == 2) |
|---|
| 775 | { ret = 0; goto release_drive; } |
|---|
| 776 | if (do_blank) { |
|---|
| 777 | if (do_blank > 100) |
|---|
| 778 | ret = libburner_format(drive_list[driveno].drive); |
|---|
| 779 | else |
|---|
| 780 | ret = libburner_blank_disc(drive_list[driveno].drive, |
|---|
| 781 | do_blank == 1); |
|---|
| 782 | if (ret<=0) |
|---|
| 783 | { ret = 36; goto release_drive; } |
|---|
| 784 | } |
|---|
| 785 | if (source_adr_count > 0) { |
|---|
| 786 | ret = libburner_payload(drive_list[driveno].drive, |
|---|
| 787 | source_adr, source_adr_count, |
|---|
| 788 | do_multi, simulate_burn, all_tracks_type); |
|---|
| 789 | if (ret<=0) |
|---|
| 790 | { ret = 38; goto release_drive; } |
|---|
| 791 | } |
|---|
| 792 | ret = 0; |
|---|
| 793 | release_drive:; |
|---|
| 794 | if (drive_is_grabbed) |
|---|
| 795 | burn_drive_release(drive_list[driveno].drive, 0); |
|---|
| 796 | |
|---|
| 797 | finish_libburn:; |
|---|
| 798 | if (burn_is_aborting(0) > 0) { |
|---|
| 799 | burn_abort(4400, burn_abort_pacifier, "libburner : "); |
|---|
| 800 | fprintf(stderr,"\nlibburner run aborted\n"); |
|---|
| 801 | exit(1); |
|---|
| 802 | } |
|---|
| 803 | |
|---|
| 804 | |
|---|
| 805 | |
|---|
| 806 | burn_finish(); |
|---|
| 807 | exit(ret); |
|---|
| 808 | } |
|---|
| 809 | |
|---|
| 810 | |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | |
|---|