raw-posix: Detect CDROM via ioctl
PATCH v3 1/1 raw-posix: Detect CDROM via ioctl
Current CDROM detection is hardcoded based on source file name. Make this smarter by attempting a CDROM specific ioctl.
This makes '-cdrom /dev/sr0' succeed with no media present.
v2:
Give ioctl check higher priority than filename check,
v3:
Actually initialize 'prio' variable
Check for ioctl success rather than absence of specific failure
--- block/raw-posix.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-)
block/raw-posix.c +18 -2
@@ -1140,9 +1140,25 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags)static int cdrom_probe_device (const char *filename) { +int fd, ret; +int prio =0 ; +if (strstart (filename,"/dev/cd" ,NULL )) -return 100 ; -return 0 ; + prio =50 ; + + fd =open (filename,O_RDONLY |O_NONBLOCK ); +if (fd <0 ) { + goto out; + } + +/* Attempt to detect via a CDROM specific ioctl */ + ret =ioctl (fd,CDROM_DRIVE_STATUS ,CDSL_CURRENT ); +if (ret >=0 ) + prio =100 ; + +close (fd); +out: +return prio; }static int cdrom_is_inserted (BlockDriverState *bs)
Signature · 1 line
1.6.5.2
Quoted 11 lines · Cole Robinson
Current CDROM detection is hardcoded based on source file name. Make this smarter by attempting a CDROM specific ioctl.
This makes '-cdrom
/dev/sr0' succeed with no media present.v2:
Give ioctl check higher priority than filename check,v3:
Actually initialize 'prio' variable
Check for ioctl success rather than absence of specific failure
Does it even compile on BSDs, Darwin etc?
[..snip..]
Signature · 1 line
mailto:[email protected]
Quoted 7 lines · malc
Quoted 5 lines · Cole Robinson
Current CDROM detection is hardcoded based on source file name. Make this smarter by attempting a CDROM specific ioctl.
This makes '-cdrom
/dev/sr0' succeed with no media present.
Quoted 9 lines
Quoted 6 lines
v2:
Give ioctl check higher priority than filename check,v3:
Actually initialize 'prio' variable
Check for ioctl success rather than absence of specific failureDoes it even compile on BSDs, Darwin etc?
The changed functions are all under #ifdef __linux__, so I assume its fine. Haven't tested though.
- Cole
Quoted 15 lines · Cole Robinson
Quoted 14 lines · malc
Quoted 11 lines · Cole Robinson
Current CDROM detection is hardcoded based on source file name. Make this smarter by attempting a CDROM specific ioctl.
This makes '-cdrom
/dev/sr0' succeed with no media present.v2:
Give ioctl check higher priority than filename check,v3:
Actually initialize 'prio' variable
Check for ioctl success rather than absence of specific failure
Quoted 5 lines
Quoted 2 lines
Does it even compile on BSDs, Darwin etc?
The changed functions are all under #ifdef
__linux__, so I assume its fine. Haven't tested though.
Fine if so, it's not immediatelly aparent from the patches nor from the commit messages though.
Signature · 1 line
mailto:[email protected]
Quoted 17 lines · malc
Quoted 15 lines · Cole Robinson
Quoted 14 lines · malc
Quoted 11 lines · Cole Robinson
Current CDROM detection is hardcoded based on source file name. Make this smarter by attempting a CDROM specific ioctl.
This makes '-cdrom
/dev/sr0' succeed with no media present.v2:
Give ioctl check higher priority than filename check,v3:
Actually initialize 'prio' variable
Check for ioctl success rather than absence of specific failure
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Does it even compile on BSDs, Darwin etc?
The changed functions are all under #ifdef
__linux__, so I assume its fine. Haven't tested though.Fine if so, it's not immediatelly aparent from the patches nor from the commit messages though.
True. I'll resend with a better commit message.
Thanks,
Cole