456 |
|
fsync(fh->fd); |
457 |
|
ioctl(fh->fd, FDFLUSH); |
458 |
|
ioctl(fh->fd, FDEJECT); |
459 |
+ |
close(fh->fd); // Close and reopen so the driver will see the media change |
460 |
+ |
fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR); |
461 |
|
} else if (fh->is_cdrom) { |
462 |
|
ioctl(fh->fd, CDROMEJECT); |
463 |
|
close(fh->fd); // Close and reopen so the driver will see the media change |
466 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
467 |
|
if (fh->is_floppy) { |
468 |
|
fsync(fh->fd); |
467 |
– |
//ioctl(fh->fd, FDFLUSH); |
468 |
– |
//ioctl(fh->fd, FDEJECT); |
469 |
|
} else if (fh->is_cdrom) { |
470 |
|
ioctl(fh->fd, CDIOCEJECT); |
471 |
|
close(fh->fd); // Close and reopen so the driver will see the media change |
547 |
|
} else if (fh->is_floppy) { |
548 |
|
char block[512]; |
549 |
|
lseek(fh->fd, 0, SEEK_SET); |
550 |
< |
return read(fh->fd, block, 512) == 512; |
550 |
> |
ssize_t actual = read(fh->fd, block, 512); |
551 |
> |
if (actual < 0) { |
552 |
> |
close(fh->fd); // Close and reopen so the driver will see the media change |
553 |
> |
fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR); |
554 |
> |
actual = read(fh->fd, block, 512); |
555 |
> |
} |
556 |
> |
return actual == 512; |
557 |
|
} else if (fh->is_cdrom) { |
558 |
|
#ifdef CDROM_MEDIA_CHANGED |
559 |
|
if (fh->cdrom_cap & CDC_MEDIA_CHANGED) { |
560 |
|
// If we don't do this, all attempts to read from a disc fail |
561 |
< |
// once the tray has been open (altough the TOC reads fine). |
561 |
> |
// once the tray has been opened (altough the TOC reads fine). |
562 |
|
// Can somebody explain this to me? |
563 |
|
if (ioctl(fh->fd, CDROM_MEDIA_CHANGED) == 1) { |
564 |
|
close(fh->fd); |