📄 dvd+rw-format.cpp
字号:
capacity |= formats[4+i+3]; if (mmc_profile==0x1A) // DVD+RW fprintf (stderr,"* %.1fGB DVD+RW media detected.\n", 2048.0*capacity/1e9); else if (mmc_profile==0x12) // DVD-RAM fprintf (stderr,"* %.1fGB DVD-RAM media detected.\n", 2048.0*capacity/1e9); else // DVD-RW fprintf (stderr,"* %.1fGB DVD-RW media in %s mode detected.\n", 2048.0*capacity/1e9, mmc_profile==0x13?"Restricted Overwrite":"Sequential"); lead_out = 0; lead_out |= formats[4+0], lead_out <<= 8; lead_out |= formats[4+1], lead_out <<= 8; lead_out |= formats[4+2], lead_out <<= 8; lead_out |= formats[4+3]; cmd[0] = 0x51; // READ DISC INFORMATION cmd[8] = sizeof(dinfo); cmd[9] = 0; if ((err=cmd.transport(READ,dinfo,sizeof(dinfo)))) { sperror ("READ DISC INFORMATION",err); if (!force) exit(1); memset (dinfo,0xff,sizeof(dinfo)); cmd[0] = 0x35; cmd[9] = 0; cmd.transport(); } do_opc = ((dinfo[0]<<8|dinfo[1])<=0x20); if (dinfo[2]&3) // non-blank media { if (!force) { if (mmc_profile==0x1A || mmc_profile==0x13 || mmc_profile==0x12) fprintf (stderr,"- media is already formatted, lead-out is currently at\n" " %d KiB which is %.1f%% of total capacity.\n", lead_out*2,(100.0*lead_out)/capacity); else fprintf (stderr,"- media is not blank\n"); offer_options: if (mmc_profile == 0x1A) fprintf (stderr,"- you have the option to re-run %s with:\n" " -lead-out to elicit lead-out relocation for better\n" " DVD-ROM compatibility, data is not affected;\n" " -force to enforce new format (not recommended)\n" " and wipe the data.\n", argv[0]); else if (mmc_profile == 0x12) fprintf (stderr,"- you have the option to re-run %s with:\n" " -format=full to perform full (lengthy) reformat;\n" " -ssa[=none|default|max]\n" " to grow, eliminate, reset to default or\n" " maximize Supplementary Spare Area.\n", argv[0]); else { fprintf (stderr,"- you have the option to re-run %s with:\n", argv[0]); if (i) fprintf (stderr, " -force[=full] to enforce new format or mode transition\n" " and wipe the data;\n"); fprintf (stderr," -blank[=full] to change to Sequential mode.\n"); } exit (0); } else if (cmd.umount()) perror (errno==EBUSY ? ":-( unable to proceed with format" : ":-( unable to umount"), exit (1); } else { if (mmc_profile==0x14 && blank==0 && !force) { fprintf (stderr,"- media is blank\n"); fprintf (stderr,"- given the time to apply full blanking procedure I've chosen\n" " to insist on -force option upon mode transition.\n"); exit (0); } force = 0; } if ((mmc_profile == 0x1A && blank) || (mmc_profile != 0x1A && compat) || (mmc_profile != 0x12 && ssa) ) { fprintf (stderr,"- illegal command-line option for this media.\n"); goto offer_options; } else if (mmc_profile == 0x1A && full) { fprintf (stderr,"- unimplemented command-line option for this media.\n"); goto offer_options; } { int fd; char *s; if ((fd=mkstemp (s=strdup("/tmp/dvd+rw.XXXXXX"))) < 0) fprintf (stderr,":-( unable to mkstemp(\"%s\")",s), exit(1); ftruncate(fd,sizeof(*progress)); unlink(s); progress = (int *)mmap(NULL,sizeof(*progress),PROT_READ|PROT_WRITE, MAP_SHARED,fd,0); close (fd); if (progress == MAP_FAILED) perror (":-( unable to mmap anonymously"), exit(1); } *progress = 0; if ((pid=fork()) == (pid_t)-1) perror (":-( unable to fork()"), exit(1); if (pid) { struct sigaction sa; const char *str; cmd.~Scsi_Command(); if (compat && force) str="relocating lead-out"; else if (blank) str="blanking"; else str="formatting"; if (gui) gui_action=str; else fprintf (stderr,"* %s .",str); sigaction (SIGALRM,NULL,&sa); sa.sa_flags &= ~SA_RESETHAND; sa.sa_flags |= SA_RESTART; sa.sa_handler = alarm_handler; sigaction (SIGALRM,&sa,NULL); alarm(1); while ((waitpid(pid,&i,0) != pid) && !WIFEXITED(i)) ; if (WEXITSTATUS(i) == 0) fprintf (stderr,"\n"); exit (0); } /* * You can suspend, terminate, etc. the parent. We will keep on * working in background... */ setsid(); signal(SIGHUP,SIG_IGN); signal(SIGINT,SIG_IGN); signal(SIGTERM,SIG_IGN); // formats[i] becomes "Format Unit Parameter List" formats[i+0] = 0; // "Reserved" formats[i+1] = 2; // "IMMED" flag formats[i+2] = 0; // "Descriptor Length" (MSB) formats[i+3] = 8; // "Descriptor Length" (LSB) handle_events(cmd); if (mmc_profile==0x1A) // DVD+RW { if (compat && force && (dinfo[2]&3)) formats[i+4+0]=formats[i+4+1]=formats[i+4+2]=formats[i+4+3]=0, formats[i+4+7] = 1; // "Restart format" cmd[0] = 0x04; // FORMAT UNIT cmd[1] = 0x11; // "FmtData" and "Format Code" cmd[5] = 0; if ((err=cmd.transport(WRITE,formats+i,12))) sperror ("FORMAT UNIT",err), exit(1); if (wait_for_unit (cmd,progress)) exit (1); if (!compat) { cmd[0] = 0x5B; // CLOSE TRACK/SESSION cmd[1] = 1; // "IMMED" flag on cmd[2] = 0; // "Stop De-Icing" cmd[9] = 0; if ((err=cmd.transport())) sperror ("STOP DE-ICING",err), exit(1); if (wait_for_unit (cmd,progress)) exit (1); } cmd[0] = 0x5B; // CLOSE TRACK/SESSION cmd[1] = 1; // "IMMED" flag on cmd[2] = 2; // "Close Session" cmd[9] = 0; if ((err=cmd.transport())) sperror ("CLOSE SESSION",err), exit(1); if (wait_for_unit (cmd,progress)) exit (1); } else if (mmc_profile==0x12) // DVD-RAM { cmd[0] = 0x04; // FORMAT UNIT if ((formats[i+4+4]>>2) == 0x01) formats[i+1] = 0, cmd[1] = 0x11; // "FmtData"|"Format Code" else if (full) formats[i+1] = 0x82,// "FOV"|"IMMED" cmd[1] = 0x11; // "FmtData"|"Format Code" else formats[i+1] = 0xA2,// "FOV"|"DCRT"|"IMMED" cmd[1] = 0x19; // "FmtData"|"CmpLst"|"Format Code" cmd[5] = 0; if ((err=cmd.transport(WRITE,formats+i,12))) sperror ("FORMAT UNIT",err), exit(1); if (wait_for_unit (cmd,progress)) exit(1); } else // DVD-RW { page05_setup (cmd,mmc_profile); if (do_opc) { cmd[0] = 0x54; // SEND OPC INFORMATION cmd[1] = 1; // "Perform OPC" cmd[9] = 0; cmd.timeout(120); // NEC units can be slooo...w if ((err=cmd.transport())) sperror ("PERFORM OPC",err), exit (1); } if (blank) // DVD-RW blanking procedure { cmd[0] = 0xA1; // BLANK cmd[1] = blank; cmd[11] = 0; if ((err=cmd.transport())) sperror ("BLANK",err), exit(1); if (wait_for_unit (cmd,progress)) exit (1); } else // DVD-RW format { if ((formats[i+4+4]>>2)==0x15) // make it really quick formats[i+4+0]=formats[i+4+1]=formats[i+4+2]=formats[i+4+3]=0; cmd[0] = 0x04; // FORMAT UNIT cmd[1] = 0x11; // "FmtData" and "Format Code" cmd[5] = 0; if ((err=cmd.transport(WRITE,formats+i,12))) sperror ("FORMAT UNIT",err), exit(1); if (wait_for_unit (cmd,progress)) exit (1); cmd[0] = 0x35; // FLUSH CACHE cmd[9] = 0; cmd.transport (); } } while (1) // Pioneer DVR-x06 needs this... { cmd[0] = 0x1B; // START/STOP UNIT cmd[1] = 0x1; // "IMMED" cmd[4] = 0; // "Stop" cmd[5] = 0; if (cmd.transport() == 0x20407) // "OP IN PROGRESS" { poll (NULL,0,333); continue; } break; }#if 0 cmd[0] = 0x1E; // ALLOW MEDIA REMOVAL cmd[5] = 0; if (cmd.transport ()) return 1; cmd[0] = 0x1B; // START/STOP UNIT cmd[4] = 0x2; // "Eject" cmd[5] = 0; if (cmd.transport()) return 1; cmd[0] = 0x1B; // START/STOP UNIT cmd[1] = 0x1; // "IMMED" cmd[4] = 0x3; // "Load" cmd[5] = 0; cmd.transport ();#endif return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -