|
Line 0
Link Here
|
|
|
1 |
--- dagrab.c.orig Sun Feb 20 01:32:46 2000 |
| 2 |
+++ dagrab.c Mon Aug 7 19:29:28 2000 |
| 3 |
@@ -94,26 +94,20 @@ |
| 4 |
#include <string.h> |
| 5 |
#include <errno.h> |
| 6 |
#include <fcntl.h> |
| 7 |
-#include <getopt.h> |
| 8 |
#include <dirent.h> |
| 9 |
#include <netdb.h> |
| 10 |
-#include <unistd.h> |
| 11 |
#include <pwd.h> |
| 12 |
#include <ctype.h> |
| 13 |
-#define __need_timeval /* needed by glibc */ |
| 14 |
-#include <time.h> |
| 15 |
-#include <linux/cdrom.h> |
| 16 |
-#ifdef USE_UCDROM |
| 17 |
-#include <linux/ucdrom.h> |
| 18 |
-#endif |
| 19 |
-#include <sys/vfs.h> |
| 20 |
#include <sys/stat.h> |
| 21 |
#include <sys/types.h> |
| 22 |
#include <sys/ioctl.h> |
| 23 |
#include <sys/socket.h> |
| 24 |
#include <netinet/in.h> |
| 25 |
+#include <sys/cdio.h> |
| 26 |
+#include <sys/param.h> |
| 27 |
+#include <sys/mount.h> |
| 28 |
#define CDDEVICE "/dev/cdrom" |
| 29 |
-#define N_BUF 8 |
| 30 |
+#define N_BUF 12 |
| 31 |
#define OVERLAP 2 |
| 32 |
#define KEYLEN 12 |
| 33 |
#define OFS 12 |
| 34 |
@@ -123,12 +117,18 @@ |
| 35 |
#define D_MODE 0660 |
| 36 |
#define CDDB_MAX 65535 |
| 37 |
#define CDDB_PORT 888 |
| 38 |
+#ifndef CDDB_PATH |
| 39 |
#define CDDB_PATH "/usr/lib/X11/xmcd/cddb" |
| 40 |
+#endif |
| 41 |
#define CDDB_HOST "freedb.freedb.org" |
| 42 |
//#define USE_CDDB (opt_save||opt_name) |
| 43 |
#define USE_CDDB opt_cddb |
| 44 |
#define PROGNAME "dagrab" |
| 45 |
#define VERSION "0.3.5" |
| 46 |
+#define CD_MSF_OFFSET 150 |
| 47 |
+#define CDROM_DATA_TRACK 4 |
| 48 |
+#define CDROM_LEADOUT 0xaa |
| 49 |
+#define CD_FRAMESIZE_RAW 2352 |
| 50 |
#define KW_TRACK 0 |
| 51 |
#define KW_FULLD 1 |
| 52 |
#define KW_AUTHOR 2 |
| 53 |
@@ -226,16 +226,16 @@ |
| 54 |
return buf; |
| 55 |
} |
| 56 |
|
| 57 |
-int cd_get_tochdr(struct cdrom_tochdr *Th) |
| 58 |
+int cd_get_tochdr(struct ioc_toc_header *Th) |
| 59 |
{ |
| 60 |
- return ioctl(cdrom_fd,CDROMREADTOCHDR,Th); |
| 61 |
+ return ioctl(cdrom_fd,CDIOREADTOCHEADER,Th); |
| 62 |
} |
| 63 |
|
| 64 |
-int cd_get_tocentry(int trk,struct cdrom_tocentry *Te,int mode) |
| 65 |
+int cd_get_tocentry(int trk,struct ioc_read_toc_single_entry *Te,int mode) |
| 66 |
{ |
| 67 |
- Te->cdte_track=trk; |
| 68 |
- Te->cdte_format=mode; |
| 69 |
- return ioctl(cdrom_fd,CDROMREADTOCENTRY,Te); |
| 70 |
+ Te->track=trk; |
| 71 |
+ Te->address_format=mode; |
| 72 |
+ return ioctl(cdrom_fd,CDIOREADTOCENTRY,Te); |
| 73 |
} |
| 74 |
|
| 75 |
void cd_read_audio(int lba,int num,char *buf) |
| 76 |
@@ -244,13 +244,13 @@ |
| 77 |
/*NOTE: if num>CDROM_NBLOCKS_BUFFER as defined in ide_cd.c (8 in linux 2.0.32) |
| 78 |
jitter correction may be required inside the block. */ |
| 79 |
{ |
| 80 |
- struct cdrom_read_audio ra; |
| 81 |
+ struct ioc_read_audio ra; |
| 82 |
|
| 83 |
- ra.addr.lba=lba; |
| 84 |
- ra.addr_format=CDROM_LBA; |
| 85 |
+ ra.address.lba=lba; |
| 86 |
+ ra.address_format=CD_LBA_FORMAT; |
| 87 |
ra.nframes=num; |
| 88 |
- ra.buf=buf; |
| 89 |
- if(ioctl(cdrom_fd,CDROMREADAUDIO,&ra)){ |
| 90 |
+ ra.buffer=buf; |
| 91 |
+ if(ioctl(cdrom_fd,CDIOCREADAUDIO,&ra)){ |
| 92 |
/*fprintf(stderr,"%s: read raw ioctl failed \n",progname);*/ |
| 93 |
fprintf(stderr,"\n%s: read raw ioctl failed at lba %d length %d: %s\n", |
| 94 |
progname,lba,num,strerror(errno)); |
| 95 |
@@ -471,7 +471,7 @@ |
| 96 |
DIR *d; |
| 97 |
struct dirent *e; |
| 98 |
char *id2,*p,*cddb,*loc; |
| 99 |
- int i,cddbs,locs; |
| 100 |
+ int i,cddbs,locs=0; |
| 101 |
char id[12]; |
| 102 |
char *path; |
| 103 |
char path2[500]; |
| 104 |
@@ -645,10 +645,10 @@ |
| 105 |
int cd_getinfo(char *cd_dev,struct cd_trk_list *tl) |
| 106 |
{ |
| 107 |
int i; |
| 108 |
- struct cdrom_tochdr Th; |
| 109 |
- struct cdrom_tocentry Te; |
| 110 |
+ struct ioc_toc_header Th; |
| 111 |
+ struct ioc_read_toc_single_entry Te; |
| 112 |
|
| 113 |
- if ((cdrom_fd=open(cd_dev,O_RDONLY|O_NONBLOCK))==-1){ |
| 114 |
+ if ((cdrom_fd=open(cd_dev,O_RDONLY))==-1){ |
| 115 |
fprintf(stderr,"%s: error opening device %s\n",progname,cd_dev); |
| 116 |
exit(1); |
| 117 |
} |
| 118 |
@@ -656,7 +656,7 @@ |
| 119 |
fprintf(stderr,"%s: read TOC ioctl failed: %s\n",progname,strerror(errno)); |
| 120 |
exit(1); |
| 121 |
} |
| 122 |
- tl->min=Th.cdth_trk0;tl->max=Th.cdth_trk1; |
| 123 |
+ tl->min=Th.starting_track;tl->max=Th.ending_track; |
| 124 |
if((tl->starts=(int *)malloc((tl->max-tl->min+2)*sizeof(int)))==NULL){ |
| 125 |
fprintf(stderr,"%s: list data allocation failed\n",progname); |
| 126 |
exit(1); |
| 127 |
@@ -668,21 +668,21 @@ |
| 128 |
|
| 129 |
for (i=tl->min;i<=tl->max;i++) |
| 130 |
{ |
| 131 |
- if(cd_get_tocentry(i,&Te,CDROM_LBA)){ |
| 132 |
+ if(cd_get_tocentry(i,&Te,CD_LBA_FORMAT)){ |
| 133 |
fprintf(stderr,"%s: read TOC entry ioctl failed: %s\n", |
| 134 |
progname,strerror(errno)); |
| 135 |
exit(1); |
| 136 |
} |
| 137 |
- tl->starts[i-tl->min]=Te.cdte_addr.lba; |
| 138 |
- tl->types[i-tl->min]=Te.cdte_ctrl&CDROM_DATA_TRACK; |
| 139 |
+ tl->starts[i-tl->min]=ntohl(Te.entry.addr.lba); |
| 140 |
+ tl->types[i-tl->min]=Te.entry.control&CDROM_DATA_TRACK; |
| 141 |
} |
| 142 |
i=CDROM_LEADOUT; |
| 143 |
- if(cd_get_tocentry(i,&Te,CDROM_LBA)){ |
| 144 |
+ if(cd_get_tocentry(i,&Te,CD_LBA_FORMAT)){ |
| 145 |
fprintf(stderr,"%s: read TOC entry ioctl failed: %s\n",progname,strerror(errno)); |
| 146 |
exit(1); |
| 147 |
} |
| 148 |
- tl->starts[tl->max-tl->min+1]=Te.cdte_addr.lba; |
| 149 |
- tl->types[tl->max-tl->min+1]=Te.cdte_ctrl&CDROM_DATA_TRACK; |
| 150 |
+ tl->starts[tl->max-tl->min+1]=ntohl(Te.entry.addr.lba); |
| 151 |
+ tl->types[tl->max-tl->min+1]=Te.entry.control&CDROM_DATA_TRACK; |
| 152 |
|
| 153 |
i=cddb_main(tl); |
| 154 |
if(i==-1) { |
| 155 |
@@ -961,7 +961,7 @@ |
| 156 |
int main(int ac,char **av) |
| 157 |
{ |
| 158 |
int i,l,disp_TOC=0; |
| 159 |
- char c; |
| 160 |
+ int c; |
| 161 |
int all_tracks=0; |
| 162 |
struct cd_trk_list tl; |
| 163 |
char cd_dev[BLEN+1]=CDDEVICE; |
| 164 |
@@ -969,10 +969,8 @@ |
| 165 |
char filter[BLEN+1] = ""; |
| 166 |
char path[500]; |
| 167 |
FILE *f; |
| 168 |
- |
| 169 |
progname=av[0]; |
| 170 |
- optind=0; |
| 171 |
- while((c=getopt(ac,av,"d:f:n:o:k:r:t:m:e:H:P:D:pshaivCSN"))!=EOF){ |
| 172 |
+ while((c=getopt(ac,av,"pshaivCSNd:f:n:o:k:r:t:m:e:H:P:D:"))!=-1){ |
| 173 |
switch(c){ |
| 174 |
case 'h':usage();break; |
| 175 |
case 'd':CPARG(cd_dev);break; |