diff --git a/.gitignore b/.gitignore index 63a1a41c..078c0f1e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ /libcdio++.pc /libcdio-*.tar.bz2 /libcdio-*.tar.gz +/libcdio-*.sig /libcdio.pc /libcdio_cdda.pc /libcdio_paranoia.pc diff --git a/lib/driver/gnu_linux.c b/lib/driver/gnu_linux.c index 74a2e256..bdce4f22 100644 --- a/lib/driver/gnu_linux.c +++ b/lib/driver/gnu_linux.c @@ -85,7 +85,8 @@ typedef enum { _AM_NONE, _AM_IOCTL, _AM_READ_CD, - _AM_READ_10 + _AM_READ_10, + _AM_MMC_RDWR } access_mode_t; typedef struct { @@ -132,6 +133,8 @@ str_to_access_mode_linux(const char *psz_access_mode) return _AM_READ_CD; else if (!strcmp(psz_access_mode, "READ_10")) return _AM_READ_10; + else if (!strcmp(psz_access_mode, "MMC_RDWR")) + return _AM_MMC_RDWR; else { cdio_warn ("unknown access type: %s. Default IOCTL used.", psz_access_mode); @@ -369,11 +372,13 @@ get_arg_linux (void *env, const char key[]) } else if (!strcmp (key, "access-mode")) { switch (_obj->access_mode) { case _AM_IOCTL: - return "ioctl"; + return "IOCTL"; case _AM_READ_CD: return "READ_CD"; case _AM_READ_10: return "READ_10"; + case _AM_MMC_RDWR: + return "MMC_RDWR"; case _AM_NONE: return "no access method"; } @@ -1068,6 +1073,7 @@ _read_mode2_sector_linux (void *p_user_data, void *p_data, lsn_t lsn, break; case _AM_IOCTL: + case _AM_MMC_RDWR: if (ioctl (p_env->gen.fd, CDROMREADMODE2, &buf) == -1) { perror ("ioctl()"); @@ -1538,6 +1544,7 @@ cdio_open_am_linux (const char *psz_orig_source, const char *access_mode) CdIo_t *ret; _img_private_t *_data; char *psz_source; + int open_access_mode; /* Access mode passed to cdio_generic_init. */ cdio_funcs_t _funcs = { .audio_get_volume = audio_get_volume_linux, @@ -1638,7 +1645,10 @@ cdio_open_am_linux (const char *psz_orig_source, const char *access_mode) ret->driver_id = DRIVER_LINUX; - if (cdio_generic_init(_data, O_RDWR|O_NONBLOCK)) { + open_access_mode = (_AM_MMC_RDWR == _data->access_mode) + ? (O_RDWR|O_NONBLOCK) : (O_RDONLY|O_NONBLOCK); + + if (cdio_generic_init(_data, open_access_mode)) { return ret; } else { cdio_generic_free (_data); diff --git a/test/.gitignore b/test/.gitignore index fb6296ca..d8fd123d 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -28,6 +28,7 @@ /testisocd /testisocd2 /testisocd2.c +/testlinux /testnrg /testnrg.c /testparanoia diff --git a/test/Makefile.am b/test/Makefile.am index 2f2f6b81..e395427f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,4 @@ -# $Id: Makefile.am,v 1.69 2008/08/31 13:38:22 flameeyes Exp $ -# -# Copyright (C) 2003, 2004, 2006, 2008 Rocky Bernstein +# Copyright (C) 2003, 2004, 2006, 2008, 2009 Rocky Bernstein # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +27,7 @@ testparanoia_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIB endif hack = check_sizeof testassert testbincue testgetdevices testischar \ - testisocd testisocd2 testiso9660 \ + testisocd testisocd2 testiso9660 testlinux \ testnrg $(testparanoia) testtoc testpregap EXTRA_PROGRAMS = testdefault @@ -49,6 +47,9 @@ testisocd2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV) testtoc_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) testtoc_CFLAGS = -DTEST_DIR=\"$(srcdir)\" +testlinux_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) +testlinux_CFLAGS = -DTEST_DIR=\"$(srcdir)\" + testpregap_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) testpregap_CFLAGS = -DTEST_DIR=\"$(srcdir)\" diff --git a/test/testlinux.c b/test/testlinux.c new file mode 100644 index 00000000..fe4f97e9 --- /dev/null +++ b/test/testlinux.c @@ -0,0 +1,85 @@ +/* -*- C -*- + Copyright (C) 2009 Rocky Bernstein + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/* + Regression test for cdio_nrgfile(). +*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include +#include + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#include + +int +main(int argc, const char *argv[]) +{ + CdIo_t *p_cdio; + char **ppsz_drives=NULL; + + cdio_loglevel_default = (argc > 1) ? CDIO_LOG_DEBUG : CDIO_LOG_INFO; + /* snprintf(psz_nrgfile, sizeof(psz_nrgfile)-1, + "%s/%s", TEST_DIR, cue_file[i]); + */ + if (!cdio_have_driver(DRIVER_LINUX)) return(77); + ppsz_drives = cdio_get_devices(DRIVER_DEVICE); + if (!ppsz_drives) { + printf("Can't find a CD-ROM drive. Skipping test.\n"); + exit(77); + } + + p_cdio = cdio_open_linux(ppsz_drives[0]); + if (p_cdio) { + const char *psz_source = cdio_get_arg(p_cdio, "source"); + if (0 != strncmp(psz_source, ppsz_drives[0], + strlen(ppsz_drives[0]))) { + fprintf(stderr, + "Got %s; should get back %s, the name we opened.\n", + psz_source, ppsz_drives[0]); + exit(1); + } + } + + + cdio_destroy(p_cdio); + p_cdio = cdio_open_am_linux(ppsz_drives[0], "MMC_RDWR"); + if (p_cdio) { + const char *psz_access_mode = cdio_get_arg(p_cdio, "access-mode"); + + if (0 != strncmp(psz_access_mode, "MMC_RDWR", strlen("MMC_RDWR"))) { + fprintf(stderr, + "Got %s; Should get back %s, the access mode requested.\n", + psz_access_mode, "MMC_RDWR"); + exit(2); + } + } + + cdio_destroy(p_cdio); + cdio_free_device_list(ppsz_drives); + + return 0; +}