Updated for better error messages
This commit is contained in:
@@ -5,19 +5,23 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/cdrom.h>
|
#include <linux/cdrom.h>
|
||||||
|
|
||||||
|
const char* program_name;
|
||||||
|
|
||||||
static inline void die(int code, const char* message){
|
static inline void die(int code, const char* message){
|
||||||
fprintf(stderr, "%s\n", message);
|
fprintf(stderr, "%s: %s\n", program_name, message);
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main(int argc, char** argv){
|
||||||
register int fd, caps;
|
register int fd, caps;
|
||||||
|
|
||||||
|
program_name = argv[0];
|
||||||
|
|
||||||
if((fd = open("/dev/cdrom", O_RDONLY | O_NONBLOCK)) == -1)
|
if((fd = open("/dev/cdrom", O_RDONLY | O_NONBLOCK)) == -1)
|
||||||
die(127, "cd_check_capabilities: Cannot open /dev/cdrom");
|
die(127, "Cannot open /dev/cdrom");
|
||||||
|
|
||||||
if((caps = ioctl(fd, CDROM_GET_CAPABILITY)) == -1)
|
if((caps = ioctl(fd, CDROM_GET_CAPABILITY)) == -1)
|
||||||
die(127, "cd_check_capabilities: ioctl failed");
|
die(127, "ioctl failed");
|
||||||
|
|
||||||
printf("This drive is capable of playing CD-R: %s\n\t\t\t"
|
printf("This drive is capable of playing CD-R: %s\n\t\t\t"
|
||||||
"CD-RW: %s\n\t\t\tDVD: %s\n\t\t\tDVD-R: %s\n",
|
"CD-RW: %s\n\t\t\tDVD: %s\n\t\t\tDVD-R: %s\n",
|
||||||
|
@@ -5,19 +5,23 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/cdrom.h>
|
#include <linux/cdrom.h>
|
||||||
|
|
||||||
|
const char* program_name;
|
||||||
|
|
||||||
static inline void die(int code, const char* message){
|
static inline void die(int code, const char* message){
|
||||||
fprintf(stderr, "%s\n", message);
|
fprintf(stderr, "%s: %s\n", program_name, message);
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main(int argc, char** argv){
|
||||||
register int fd;
|
register int fd;
|
||||||
|
|
||||||
|
program_name = argv[0];
|
||||||
|
|
||||||
if((fd = open("/dev/cdrom", O_RDONLY | O_NONBLOCK)) == -1)
|
if((fd = open("/dev/cdrom", O_RDONLY | O_NONBLOCK)) == -1)
|
||||||
die(127, "cd_check_eject: Cannot open /dev/cdrom");
|
die(127, "Cannot open /dev/cdrom");
|
||||||
|
|
||||||
if(ioctl(fd, CDROMEJECT) == -1)
|
if(ioctl(fd, CDROMEJECT) == -1)
|
||||||
die(127, "cd_check_eject: ioctl() failed");
|
die(127, "ioctl() failed");
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
@@ -1,28 +1,37 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/cdrom.h>
|
#include <linux/cdrom.h>
|
||||||
|
|
||||||
|
const char* program_name;
|
||||||
|
|
||||||
static inline void die(int code, const char* message){
|
static inline void die(int code, const char* message){
|
||||||
fprintf(stderr, "%s\n", message);
|
fprintf(stderr, "%s: %s\n", program_name, message);
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main(int argc, char** argv){
|
||||||
register int fd;
|
register int fd;
|
||||||
struct cdrom_tocentry toc_entry;
|
struct cdrom_tocentry toc_entry;
|
||||||
struct cdrom_msf start_stop;
|
struct cdrom_msf start_stop;
|
||||||
|
|
||||||
if((fd = open("/dev/cdrom", O_RDONLY)) == -1)
|
program_name = argv[0];
|
||||||
die(127, "cd_check_read: Cannot open /dev/cdrom");
|
|
||||||
|
if((fd = open("/dev/cdrom", O_RDONLY)) == -1){
|
||||||
|
if(errno == ENOMEDIUM)
|
||||||
|
die(127, "No CD in drive");
|
||||||
|
else
|
||||||
|
die(127, "Cannot open /dev/cdrom");
|
||||||
|
}
|
||||||
|
|
||||||
toc_entry.cdte_track = 1;
|
toc_entry.cdte_track = 1;
|
||||||
toc_entry.cdte_format = CDROM_MSF;
|
toc_entry.cdte_format = CDROM_MSF;
|
||||||
|
|
||||||
if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1)
|
if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1)
|
||||||
die(127, "cd_check_read: ioctl() failed");
|
die(127, "ioctl() failed");
|
||||||
|
|
||||||
start_stop.cdmsf_min0 = toc_entry.cdte_addr.msf.minute;
|
start_stop.cdmsf_min0 = toc_entry.cdte_addr.msf.minute;
|
||||||
start_stop.cdmsf_sec0 = toc_entry.cdte_addr.msf.second;
|
start_stop.cdmsf_sec0 = toc_entry.cdte_addr.msf.second;
|
||||||
@@ -32,20 +41,20 @@ int main(){
|
|||||||
toc_entry.cdte_format = CDROM_MSF;
|
toc_entry.cdte_format = CDROM_MSF;
|
||||||
|
|
||||||
if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1)
|
if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1)
|
||||||
die(127, "cd_check_read: ioctl() failed");
|
die(127, "ioctl() failed");
|
||||||
|
|
||||||
start_stop.cdmsf_min1 = toc_entry.cdte_addr.msf.minute;
|
start_stop.cdmsf_min1 = toc_entry.cdte_addr.msf.minute;
|
||||||
start_stop.cdmsf_sec1 = toc_entry.cdte_addr.msf.second;
|
start_stop.cdmsf_sec1 = toc_entry.cdte_addr.msf.second;
|
||||||
start_stop.cdmsf_frame1 = toc_entry.cdte_addr.msf.frame;
|
start_stop.cdmsf_frame1 = toc_entry.cdte_addr.msf.frame;
|
||||||
|
|
||||||
if(ioctl(fd, CDROMPLAYMSF, &start_stop) == -1)
|
if(ioctl(fd, CDROMPLAYMSF, &start_stop) == -1)
|
||||||
die(127, "cd_check_read: ioctl() failed");
|
die(127, "ioctl() failed");
|
||||||
|
|
||||||
printf("Press anything to stop playing.\n");
|
printf("Press anything to stop playing.\n");
|
||||||
getchar();
|
getchar();
|
||||||
|
|
||||||
if(ioctl(fd, CDROMSTOP) == -1)
|
if(ioctl(fd, CDROMSTOP) == -1)
|
||||||
die(127, "cd_check_read: ioctl() failed");
|
die(127, "ioctl() failed");
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -6,26 +6,30 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/cdrom.h>
|
#include <linux/cdrom.h>
|
||||||
|
|
||||||
|
const char* program_name;
|
||||||
|
|
||||||
static inline void die(int code, const char* message){
|
static inline void die(int code, const char* message){
|
||||||
fprintf(stderr, "%s\n", message);
|
fprintf(stderr, "%s: %s\n", program_name, message);
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main(int argc, char** argv){
|
||||||
register int fd;
|
register int fd;
|
||||||
register unsigned char i;
|
register unsigned char i;
|
||||||
struct cdrom_tochdr toc_hdr;
|
struct cdrom_tochdr toc_hdr;
|
||||||
struct cdrom_tocentry toc_entry;
|
struct cdrom_tocentry toc_entry;
|
||||||
|
|
||||||
|
program_name = argv[0];
|
||||||
|
|
||||||
if((fd = open("/dev/cdrom", O_RDONLY)) == -1){
|
if((fd = open("/dev/cdrom", O_RDONLY)) == -1){
|
||||||
if(errno == ENOMEDIUM)
|
if(errno == ENOMEDIUM)
|
||||||
die(127, "cd_check_read_toc: No CD in drive");
|
die(127, "No CD in drive");
|
||||||
else
|
else
|
||||||
die(127, "cd_check_read_toc: Cannot open /dev/cdrom");
|
die(127, "Cannot open /dev/cdrom");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ioctl(fd, CDROMREADTOCHDR, &toc_hdr) == -1)
|
if(ioctl(fd, CDROMREADTOCHDR, &toc_hdr) == -1)
|
||||||
die(127, "cd_check_read_toc: Cannot get header");
|
die(127, "Cannot get header");
|
||||||
|
|
||||||
printf("First track: %d\nLast track: %d\n\n trackno) length\n",
|
printf("First track: %d\nLast track: %d\n\n trackno) length\n",
|
||||||
toc_hdr.cdth_trk0, toc_hdr.cdth_trk1);
|
toc_hdr.cdth_trk0, toc_hdr.cdth_trk1);
|
||||||
@@ -35,7 +39,7 @@ int main(){
|
|||||||
toc_entry.cdte_format = CDROM_MSF;
|
toc_entry.cdte_format = CDROM_MSF;
|
||||||
|
|
||||||
if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1)
|
if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1)
|
||||||
die(127, "cd_check_read_toc: Cannot get table of contents");
|
die(127, "Cannot get table of contents");
|
||||||
|
|
||||||
printf(" %2d)\t%02d:%02d.%02d\n", i, toc_entry.cdte_addr.msf.minute,
|
printf(" %2d)\t%02d:%02d.%02d\n", i, toc_entry.cdte_addr.msf.minute,
|
||||||
toc_entry.cdte_addr.msf.second,
|
toc_entry.cdte_addr.msf.second,
|
||||||
|
Reference in New Issue
Block a user