dvdinfo.c
上传用户:aoeyumen
上传日期:2007-01-06
资源大小:3329k
文件大小:2k
- /*
- * A noddy program for getting and printing some info from the
- * DVD-ROM drive.
- */
- #include <stdio.h>
- #include <fcntl.h>
- #if defined(__OpenBSD__)
- # include <sys/dvdio.h>
- #elif defined(__linux__)
- # include <linux/cdrom.h>
- #else
- # error "Need the DVD ioctls"
- #endif
- #include <sys/ioctl.h>
- #include <errno.h>
- #define DVD "/dev/cdrom"
- int GetASF(int fd)
- {
- dvd_authinfo ai;
- ai.type = DVD_LU_SEND_ASF;
- ai.lsasf.agid = 0;
- ai.lsasf.asf = 0;
- if (ioctl(fd, DVD_AUTH, &ai)) {
- printf("GetASF failedn");
- return 0;
- }
- printf("%sAuthenticatedn", (ai.lsasf.asf) ? "" : "not ");
- return 1;
- }
- int GetPhysical(int fd)
- {
- dvd_struct d;
- int layer = 0, layers = 4;
- d.physical.type = DVD_STRUCT_PHYSICAL;
- while (layer < layers) {
- d.physical.layer_num = layer;
-
- if (ioctl(fd, DVD_READ_STRUCT, &d)<0)
- {
- printf("Could not read Physical layer %dn", layer);
- return 0;
- }
- layers = d.physical.layer[layer].nlayers + 1;
- printf("Layer %d[%d]n", layer, layers);
- printf(" Book Version: %dn", d.physical.layer[layer].book_version);
- printf(" Book Type: %dn", d.physical.layer[layer].book_type);
- printf(" Min Rate: %dn", d.physical.layer[layer].min_rate);
- printf(" Disk Size: %dn", d.physical.layer[layer].disc_size);
- printf(" Layer Type: %dn", d.physical.layer[layer].layer_type);
- printf(" Track Path: %dn", d.physical.layer[layer].track_path);
- printf(" Num Layers: %dn", d.physical.layer[layer].nlayers);
- printf(" Track Density: %dn", d.physical.layer[layer].track_density);
- printf(" Linear Density: %dn", d.physical.layer[layer].linear_density);
- printf(" BCA: %dn", d.physical.layer[layer].bca);
- printf(" Start Sector %#xn", d.physical.layer[layer].start_sector);
- printf(" End Sector %#xn", d.physical.layer[layer].end_sector);
- printf(" End Sector L0 %#xn", d.physical.layer[layer].end_sector_l0);
- ++layer;
- }
- return 1;
- }
- int GetCopyright(int fd)
- {
- dvd_struct d;
- d.copyright.type = DVD_STRUCT_COPYRIGHT;
- d.copyright.layer_num = 0;
-
- if (ioctl(fd, DVD_READ_STRUCT, &d)<0)
- {
- printf("Could not read Copyright Structn");
- return 0;
- }
- printf("Copyright: CPST=%d, RMI=%#02xn", d.copyright.cpst, d.copyright.rmi);
- return 1;
- }
- int main(int ac, char **av)
- {
- int fd;
- char *device = DVD;
- if (ac > 1)
- device = av[1];
- fd = open(device, O_RDONLY | O_NONBLOCK);
- if (fd < 0) {
- printf("unable to open dvd drive (%s).n", device);
- return 1;
- }
- GetASF(fd);
- GetPhysical(fd);
- GetCopyright(fd);
- return 0;
- }