Solved Random seek on CD-ROM drive

I wish to exercise my CD-ROM drive, to keep the dust off the lens. On Linux I run (as root) a C program I wrote which seeks back and forth, reading a single block each time as it goes. On FreeBSD this program doesn't get too far. I can open the device and seek to (say) block 1. But when I try to read the block, I get error 22 (EINVAL). It fails on the first read, at block 1, whether or not the device is mounted (-t cd9660). How do I proceed?

Code:
  lo_fd=Open(ar_argv[1],
             O_RDONLY,
             0
            );

  lo_high_bit=1;

  while(lo_high_bit>0)
  {
    if(lseek(lo_fd,
             lo_high_bit,
             SEEK_SET
            )
       ==
       (off_t)-1
      )
    {
      lo_high_bit>>=1;

      break;
    }

    if(read(lo_fd,
            lo_buffer,
            1
           )
       !=
       1
      )
    {
      lo_high_bit>>=1;

      break;
    }

    lo_high_bit<<=1;
  }
 
SOLVED: it turns out there were two problems: I was seeking to byte 1 (not sector 1), and reading just one byte.

fstat(1) on that device yields a block size of 4096.

If I seek to 4096 and read 4096 bytes, it works.

If I seek to 2048 and read 2048 bytes, it works.

If I seek to 2048 and read 1024 bytes, I get EINVAL on the read().

If I seek to 1024 and read 2048 bytes, I get EINVAL on the read().
 
Back
Top