One more time, go over logic of get_drives_with_cap.

This commit is contained in:
rocky
2006-03-27 02:48:41 +00:00
parent 8b24c3a47e
commit 10942d5ba3
4 changed files with 67 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
/*
$Id: drives.cpp,v 1.3 2006/02/09 18:16:29 rocky Exp $
$Id: drives.cpp,v 1.4 2006/03/27 02:48:41 rocky Exp $
Copyright (C) 2003, 2004, 2006 Rocky Bernstein <rocky@panix.com>
@@ -54,7 +54,7 @@ print_drive_class(const char *psz_msg, cdio_fs_anal_t bitmask,
char **ppsz_cd_drives=NULL, **c;
printf("%s...\n", psz_msg);
ppsz_cd_drives = getDevices(NULL, bitmask);
ppsz_cd_drives = getDevices(NULL, bitmask, b_any);
if (NULL != ppsz_cd_drives)
for( c = ppsz_cd_drives; *c != NULL; c++ ) {
printf("Drive %s\n", *c);
@@ -82,9 +82,12 @@ main(int argc, const char *argv[])
freeDeviceList(ppsz_cd_drives);
print_drive_class("All CD-ROM drives (again)", CDIO_FS_MATCH_ALL);
print_drive_class("CD-DA drives...", CDIO_FS_AUDIO);
print_drive_class("All drives with ISO 9660...", CDIO_FS_ISO_9660);
print_drive_class("VCD drives...",
print_drive_class("CD-ROM drives with a CD-DA loaded...", CDIO_FS_AUDIO);
print_drive_class("CD-ROM drives with some sort of ISO 9660 filesystem...",
(CDIO_FS_ISO_9660
|CDIO_FS_ISO_HFS
|CDIO_FS_ISO_9660_INTERACTIVE), true);
print_drive_class("(S)VCD drives...",
(CDIO_FS_ANAL_SVCD|CDIO_FS_ANAL_CVD|
CDIO_FS_ANAL_VIDEOCD|CDIO_FS_UNKNOWN), true);
return 0;

View File

@@ -1,5 +1,5 @@
/*
$Id: drives.c,v 1.3 2006/02/09 18:16:29 rocky Exp $
$Id: drives.c,v 1.4 2006/03/27 02:48:41 rocky Exp $
Copyright (C) 2003, 2004, 2006 Rocky Bernstein <rocky@panix.com>
@@ -84,9 +84,13 @@ main(int argc, const char *argv[])
/* Print out a list of CD-drives the harder way. */
print_drive_class("All CD-ROM drives (again)", CDIO_FS_MATCH_ALL, false);
print_drive_class("CD-DA drives...", CDIO_FS_AUDIO, false);
print_drive_class("All drives with ISO 9660...", CDIO_FS_ISO_9660, false);
print_drive_class("VCD drives...",
print_drive_class("CD-ROM drives with a CD-DA loaded...",
CDIO_FS_AUDIO, false);
print_drive_class("CD-ROM drives with some sort of ISO 9660 filesystem...",
(CDIO_FS_ISO_9660
|CDIO_FS_ISO_HFS
|CDIO_FS_ISO_9660_INTERACTIVE), true);
print_drive_class("(S)VCD drives...",
(CDIO_FS_ANAL_SVCD|CDIO_FS_ANAL_CVD|
CDIO_FS_ANAL_VIDEOCD|CDIO_FS_UNKNOWN), true);
return 0;

View File

@@ -1,5 +1,5 @@
/* -*- c -*-
$Id: device.h,v 1.32 2006/02/02 04:37:29 rocky Exp $
$Id: device.h,v 1.33 2006/03/27 02:48:41 rocky Exp $
Copyright (C) 2005, 2006 Rocky Bernstein <rocky@panix.com>
@@ -311,10 +311,31 @@ extern "C" {
the capabilities listed by the capabities parameter. If
search_devices is NULL, then we'll search all possible CD drives.
Capabilities have two parts to them, a "filesystem" part and an
"analysis" part.
The filesystem part is mutually exclusive. For example either the
filesystem is at most one of the High-Sierra, UFS, or HFS, ISO9660,
fileystems. Valid combinations of say HFS and ISO9660 are
specified as a separate "filesystem".
Capabilities on the other hand are not mutually exclusive. For example
a filesystem may have none, either, or both of the XA or Rock-Ridge
extension properties.
If "b_any" is set false then every capability listed in the
extended portion of capabilities (i.e. not the basic filesystem)
must be satisified. If "any" is set true, then if any of the
capabilities matches, we call that a success.
analysis portion of capabilities (i.e. not the basic filesystem)
must be satisified. If no analysis capabilities are specified,
that's a match.
If "b_any" is set true, then if any of the analysis capabilities
matches, we call that a success.
In either case, you can specify in the filesystem portion
different filesystem types and a match will succeed only if one of
them matches. (It doesn't make sense to try to match on *all* of
the filesystems as a CD can only have one). Again, if no fileystem
is specified, that's a match.
To find a CD-drive of any type, use the mask CDIO_FS_MATCH_ALL.

View File

@@ -1,5 +1,5 @@
/*
$Id: device.c,v 1.36 2006/03/26 20:47:55 rocky Exp $
$Id: device.c,v 1.37 2006/03/27 02:48:41 rocky Exp $
Copyright (C) 2005, 2006 Rocky Bernstein <rocky@panix.com>
@@ -579,7 +579,7 @@ cdio_get_devices_with_cap (/*in*/ char* search_devices[],
char **
cdio_get_devices_with_cap_ret (/*in*/ char* search_devices[],
cdio_fs_anal_t capabilities, bool any,
cdio_fs_anal_t need_cap, bool b_any,
/*out*/ driver_id_t *p_driver_id)
{
char **ppsz_drives=search_devices;
@@ -596,7 +596,7 @@ cdio_get_devices_with_cap_ret (/*in*/ char* search_devices[],
if (!ppsz_drives) return NULL;
if (capabilities == CDIO_FS_MATCH_ALL) {
if (need_cap == CDIO_FS_MATCH_ALL) {
/* Duplicate drives into drives_ret. */
char **d = ppsz_drives;
@@ -604,8 +604,7 @@ cdio_get_devices_with_cap_ret (/*in*/ char* search_devices[],
cdio_add_device_list(&ppsz_drives_ret, *d, &i_drives);
}
} else {
cdio_fs_anal_t got_fs=0;
cdio_fs_anal_t need_fs = CDIO_FSTYPE(capabilities);
const cdio_fs_anal_t need_fs = CDIO_FSTYPE(need_cap);
char **d = ppsz_drives;
for( ; *d != NULL; d++ ) {
@@ -616,13 +615,26 @@ cdio_get_devices_with_cap_ret (/*in*/ char* search_devices[],
cdio_iso_analysis_t cdio_iso_analysis;
if (CDIO_INVALID_TRACK != i_first_track) {
got_fs = cdio_guess_cd_type(p_cdio, 0, i_first_track,
&cdio_iso_analysis);
/* Match on fs and add */
if ( (CDIO_FS_UNKNOWN == need_fs || CDIO_FSTYPE(got_fs & need_fs)) )
{
bool doit = any ? true : (got_fs & need_fs) == need_fs;
if (doit)
const cdio_fs_anal_t got_cap =
cdio_guess_cd_type(p_cdio, 0, i_first_track, &cdio_iso_analysis);
/* Match on filesystem. Here either we don't know what the
filesystem is - automatic match, or we no that the file
system is in the set of those specified.
We refine the logic further after this initial test. */
if ( CDIO_FS_UNKNOWN == need_fs
|| (CDIO_FSTYPE(got_cap) & need_fs) ) {
/* Match on analysis type. If we haven't set any
analysis type, then an automatic match. Otherwise
a match is determined by whether we need all
analysis types or any of them. */
const cdio_fs_anal_t need_anal = need_cap & ~CDIO_FS_MASK;
const cdio_fs_anal_t got_anal = got_cap & ~CDIO_FS_MASK;
const bool b_match = !need_anal
|| (b_any
? (got_anal & need_anal) != 0
: (got_anal & need_anal) == need_anal);
if (b_match)
cdio_add_device_list(&ppsz_drives_ret, *d, &i_drives);
}
}