Menu

#13 hdparm does not work on read only devices like cdroms

closed-fixed
nobody
None
5
2008-06-02
2008-03-04
Anonymous
No

hdparm does not work on a read only mounted device like a cdrom.

hdparm uses the following sequence to open the device:

static int open_flags = O_RDWR|O_NONBLOCK;
...
fd = open (devname, open_flags);
if (fd < 0) {
if (errno == EROFS) {
open_flags &= ~O_WRONLY;
fd = open (devname, open_flags);

So it tries to open the device in read/write mode and it looks like it tries to fall back to read only if that fails. Unfortunatly this does not work, since the constants are defined as follows (linux, glibc, /usr/include/bits/fcntl.h, /usr/include/asm-generic/fcntl.h):

#define O_RDONLY 00
#define O_WRONLY 01
#define O_RDWR 02

So the bitwise "AND" operation does not do anything, the open_flags stay unchanged. It looks like this should be either

open_flags &= ~O_RDWR

or

open_flags = (open_flags & ~O_RDWR) | O_RDONLY;

I used the second sequence and now hdparm works for me again.

regards,
Jean

Discussion

  • Mark Lord

    Mark Lord - 2008-06-02
    • status: open --> closed-fixed
     
  • Mark Lord

    Mark Lord - 2008-06-02

    Logged In: YES
    user_id=350110
    Originator: NO

    Fixed in hdparm-8.7.

    Thanks for finding and reporting this!

     

Log in to post a comment.