Index: usr.sbin/burncd/burncd.c =================================================================== --- usr.sbin/burncd/burncd.c (revision 199016) +++ usr.sbin/burncd/burncd.c (working copy) @@ -65,6 +65,7 @@ void do_DAO(int fd, int, int); void do_TAO(int fd, int, int, int); void do_format(int, int, char *); +void wait_for_ready(int); int write_file(int fd, struct track_info *); int roundup_blocks(struct track_info *); void cue_ent(struct cdr_cue_entry *, int, int, int, int, int, int, int); @@ -219,6 +220,8 @@ break; last = pct; } + wait_for_ready(fd); + if (!quiet) printf("\n"); continue; @@ -322,6 +325,7 @@ err_set_exit(NULL); err(EX_IOERR, "ioctl(CDRIOCSETBLOCKSIZE)"); } + wait_for_ready(fd); if (eject) if (ioctl(fd, CDIOCEJECT) < 0) @@ -600,6 +604,27 @@ fprintf(stderr, "\n"); } +void +wait_for_ready(int fd) +{ + int timeout = 10 * 1000; + + while (timeout > 0) { + /* + * CDIOCRESET issues ATAPI_TEST_UNIT_READY command. + */ + if (ioctl(fd, CDIOCRESET) == 0) + return; + else if (errno != EBUSY) + err(EX_IOERR, "ioctl(CDIOCRESET)"); + + usleep(500 * 1000); + timeout -= 500; + } + + errx(EX_IOERR, "timed out while waiting for the drive to become ready"); +} + int write_file(int fd, struct track_info *track_info) {