Discussion:
[libdvdcss-devel] [PATCH] cygwin: Use Win32 APIs for accessing DVDs
Diego Biurrun
2013-02-01 12:05:43 UTC
Permalink
Signed-off-by: Diego Biurrun <***@biurrun.de>
---
configure.ac | 1 -
src/ioctl.c | 41 +++++++++++++++++++----------------------
src/ioctl.h | 8 ++++++--
3 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/configure.ac b/configure.ac
index 44ff25c..ca2e708 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,6 @@ case x"${target_os}" in
yes
#endif],
AC_DEFINE(SYS_CYGWIN, 1, Have a Cygwin system.))
- AC_DEFINE(WIN32, 1, Using Win32.)
;;
xbeos*)
AC_DEFINE(SYS_BEOS, 1, Have a BeOS system.)
diff --git a/src/ioctl.c b/src/ioctl.c
index 5c7e615..3ebeb07 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -31,14 +31,15 @@
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include "config.h"
-
#include <stdio.h>
-
#include <string.h> /* memcpy(), memset() */
#include <sys/types.h>

-#if defined( WIN32 )
+#include "config.h"
+#include "common.h"
+#include "ioctl.h"
+
+#if defined( WIN32_DVD_API )
# include <windows.h>
# include <winioctl.h>
#elif defined ( SYS_OS2 )
@@ -90,10 +91,6 @@
# include <sys/dcmd_cam.h>
#endif

-#include "common.h"
-
-#include "ioctl.h"
-
/*****************************************************************************
* Local prototypes, BeOS specific
*****************************************************************************/
@@ -119,7 +116,7 @@ static int SolarisSendUSCSI( int fd, struct uscsi_cmd *p_sc );
/*****************************************************************************
* Local prototypes, win32 (aspi) specific
*****************************************************************************/
-#if defined( WIN32 )
+#if defined( WIN32_DVD_API )
static void WinInitSPTD ( SCSI_PASS_THROUGH_DIRECT *, int );
static void WinInitSSC ( struct SRB_ExecSCSICmd *, int );
static int WinSendSSC ( int, struct SRB_ExecSCSICmd * );
@@ -213,7 +210,7 @@ int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )

*pi_copyright = dvdbs.copyrightProtectionSystemType;

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
INIT_SPTD( GPCMD_READ_DVD_STRUCTURE, 8 );
@@ -373,7 +370,7 @@ int ioctl_ReadDiscKey( int i_fd, int *pi_agid, uint8_t *p_key )

memcpy( p_key, dvdbs.discKeyStructures, DVD_DISCKEY_SIZE );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -541,7 +538,7 @@ int ioctl_ReadTitleKey( int i_fd, int *pi_agid, int i_pos, uint8_t *p_key )

memcpy( p_key, dvdbs.titleKeyValue, DVD_KEY_SIZE );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -687,7 +684,7 @@ int ioctl_ReportAgid( int i_fd, int *pi_agid )

*pi_agid = dvdbs.grantID;

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
ULONG id;
@@ -808,7 +805,7 @@ int ioctl_ReportChallenge( int i_fd, int *pi_agid, uint8_t *p_challenge )

memcpy( p_challenge, dvdbs.challengeKeyValue, DVD_CHALLENGE_SIZE );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -940,7 +937,7 @@ int ioctl_ReportASF( int i_fd, int *pi_remove_me, int *pi_asf )

*pi_asf = dvdbs.successFlag;

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1075,7 +1072,7 @@ int ioctl_ReportKey1( int i_fd, int *pi_agid, uint8_t *p_key )

memcpy( p_key, dvdbs.key1Value, DVD_KEY_SIZE );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1192,7 +1189,7 @@ int ioctl_InvalidateAgid( int i_fd, int *pi_agid )

i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1320,7 +1317,7 @@ int ioctl_SendChallenge( int i_fd, int *pi_agid, uint8_t *p_challenge )

i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1457,7 +1454,7 @@ int ioctl_SendKey2( int i_fd, int *pi_agid, uint8_t *p_key )

i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1603,7 +1600,7 @@ int ioctl_ReportRPC( int i_fd, int *p_type, int *p_mask, int *p_scheme )
*p_mask = dvdbs.driveRegion;
*p_scheme = dvdbs.rpcScheme;

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1746,7 +1743,7 @@ int ioctl_SendRPC( int i_fd, int i_pdrc )

i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
INIT_SPTD( GPCMD_SEND_KEY, 8 );
@@ -1969,7 +1966,7 @@ static int SolarisSendUSCSI( int i_fd, struct uscsi_cmd *p_sc )
}
#endif

-#if defined( WIN32 )
+#if defined( WIN32_DVD_API )
/*****************************************************************************
* WinInitSPTD: initialize a sptd structure
*****************************************************************************
diff --git a/src/ioctl.h b/src/ioctl.h
index c0bc7d5..bc423b8 100644
--- a/src/ioctl.h
+++ b/src/ioctl.h
@@ -24,6 +24,10 @@
#ifndef DVDCSS_IOCTL_H
#define DVDCSS_IOCTL_H

+#if defined( WIN32 ) || defined( SYS_CYGWIN )
+# define WIN32_DVD_API
+#endif
+
int ioctl_ReadCopyright ( int, int, int * );
int ioctl_ReadDiscKey ( int, int *, uint8_t * );
int ioctl_ReadTitleKey ( int, int *, int, uint8_t * );
@@ -101,7 +105,7 @@ int ioctl_SendRPC ( int, int );
/*****************************************************************************
* Common macro, win32 specific
*****************************************************************************/
-#if defined( WIN32 )
+#if defined( WIN32_DVD_API )
#define INIT_SPTD( TYPE, SIZE ) \
DWORD tmp; \
SCSI_PASS_THROUGH_DIRECT sptd; \
@@ -194,7 +198,7 @@ typedef union dvd_authinfo dvd_authinfo;
/*****************************************************************************
* win32 ioctl specific
*****************************************************************************/
-#if defined( WIN32 )
+#if defined( WIN32_DVD_API )

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
--
1.7.9.5
Jean-Baptiste Kempf
2013-02-01 12:37:37 UTC
Permalink
Post by Diego Biurrun
+#if defined( WIN32 ) || defined( SYS_CYGWIN )
+# define WIN32_DVD_API
+#endif
I don't see the point. CYGWIN should have WIN32 defined too.
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Diego Biurrun
2013-02-01 12:46:42 UTC
Permalink
Post by Jean-Baptiste Kempf
Post by Diego Biurrun
+#if defined( WIN32 ) || defined( SYS_CYGWIN )
+# define WIN32_DVD_API
+#endif
I don't see the point. CYGWIN should have WIN32 defined too.
No, why? Cygwin attempts to be a POSIX and not a Windows environment ...

Diego
Diego Biurrun
2013-02-01 12:50:17 UTC
Permalink
Post by Diego Biurrun
Post by Jean-Baptiste Kempf
Post by Diego Biurrun
+#if defined( WIN32 ) || defined( SYS_CYGWIN )
+# define WIN32_DVD_API
+#endif
I don't see the point. CYGWIN should have WIN32 defined too.
No, why? Cygwin attempts to be a POSIX and not a Windows environment ...
13:46 < DonDiego> say, should WIN32 or _WIN32 be defined for Cygwin?
13:47 < jturney> no

Diego
Diego Biurrun
2013-02-01 12:52:21 UTC
Permalink
Post by Diego Biurrun
Post by Diego Biurrun
Post by Jean-Baptiste Kempf
Post by Diego Biurrun
+#if defined( WIN32 ) || defined( SYS_CYGWIN )
+# define WIN32_DVD_API
+#endif
I don't see the point. CYGWIN should have WIN32 defined too.
No, why? Cygwin attempts to be a POSIX and not a Windows environment ...
13:46 < DonDiego> say, should WIN32 or _WIN32 be defined for Cygwin?
13:47 < jturney> no
.. and also ..

http://cygwin.com/faq-nochunks.html#faq.programming.preprocessor

Diego
Jean-Baptiste Kempf
2013-02-01 12:58:18 UTC
Permalink
Post by Diego Biurrun
Post by Jean-Baptiste Kempf
Post by Diego Biurrun
+#if defined( WIN32 ) || defined( SYS_CYGWIN )
+# define WIN32_DVD_API
+#endif
I don't see the point. CYGWIN should have WIN32 defined too.
No, why? Cygwin attempts to be a POSIX and not a Windows environment ...
Please explain all the defines then:
#if defined( WIN32 ) && !defined( SYS_CYGWIN )
all around the code.

Including windows.h will define WIN32 anyway.
There is no reason to support this mess: if you use Win32 APIs, you
use the define WIN32, not a new WIN32_DVD_API

Best regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Diego Biurrun
2013-02-01 13:34:21 UTC
Permalink
Post by Jean-Baptiste Kempf
Post by Diego Biurrun
Post by Jean-Baptiste Kempf
Post by Diego Biurrun
+#if defined( WIN32 ) || defined( SYS_CYGWIN )
+# define WIN32_DVD_API
+#endif
I don't see the point. CYGWIN should have WIN32 defined too.
No, why? Cygwin attempts to be a POSIX and not a Windows environment ...
#if defined( WIN32 ) && !defined( SYS_CYGWIN )
all around the code.
I overlooked these, thanks for noticing, updated patch coming up ...
Post by Jean-Baptiste Kempf
Including windows.h will define WIN32 anyway.
How is that the case? Cygwin only defines that if -mwin32 is passed to
gcc on the command line ...

Diego
Jean-Baptiste Kempf
2013-02-01 15:05:17 UTC
Permalink
Post by Diego Biurrun
How is that the case? Cygwin only defines that if -mwin32 is passed to
gcc on the command line ...
Then pass this to the command line.

Best regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Diego Biurrun
2013-02-01 15:10:05 UTC
Permalink
Post by Jean-Baptiste Kempf
Post by Diego Biurrun
How is that the case? Cygwin only defines that if -mwin32 is passed to
gcc on the command line ...
Then pass this to the command line.
That would kind of defeat the purpose of using Cygwin in the first
place, wouldn't it ..?

Diego

Diego Biurrun
2013-02-01 13:41:04 UTC
Permalink
Signed-off-by: Diego Biurrun <***@biurrun.de>
---

Now also fixing some leftover SYS_CYGWIN symbols ..

configure.ac | 1 -
src/device.c | 2 +-
src/device.h | 4 ++--
src/ioctl.c | 41 +++++++++++++++++++----------------------
src/ioctl.h | 8 ++++++--
5 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/configure.ac b/configure.ac
index 44ff25c..ca2e708 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,6 @@ case x"${target_os}" in
yes
#endif],
AC_DEFINE(SYS_CYGWIN, 1, Have a Cygwin system.))
- AC_DEFINE(WIN32, 1, Using Win32.)
;;
xbeos*)
AC_DEFINE(SYS_BEOS, 1, Have a BeOS system.)
diff --git a/src/device.c b/src/device.c
index 46a936a..8bee887 100644
--- a/src/device.c
+++ b/src/device.c
@@ -49,7 +49,7 @@
# include <limits.h>
#endif

-#if defined( WIN32 ) && !defined( SYS_CYGWIN )
+#if defined( WIN32 )
# include <io.h> /* read() */
#else
# include <sys/uio.h> /* struct iovec */
diff --git a/src/device.h b/src/device.h
index ddaa18e..8091bb6 100644
--- a/src/device.h
+++ b/src/device.h
@@ -29,7 +29,7 @@
/*****************************************************************************
* iovec structure: vectored data entry
*****************************************************************************/
-#if defined( WIN32 ) && !defined( SYS_CYGWIN )
+#if defined( WIN32 )
# include <io.h> /* read() */
#else
# include <sys/types.h>
@@ -38,7 +38,7 @@

#include "dvdcss/dvdcss.h"

-#if defined( WIN32 ) && !defined( SYS_CYGWIN )
+#if defined( WIN32 )
struct iovec
{
void *iov_base; /* Pointer to data. */
diff --git a/src/ioctl.c b/src/ioctl.c
index 5c7e615..3ebeb07 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -31,14 +31,15 @@
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include "config.h"
-
#include <stdio.h>
-
#include <string.h> /* memcpy(), memset() */
#include <sys/types.h>

-#if defined( WIN32 )
+#include "config.h"
+#include "common.h"
+#include "ioctl.h"
+
+#if defined( WIN32_DVD_API )
# include <windows.h>
# include <winioctl.h>
#elif defined ( SYS_OS2 )
@@ -90,10 +91,6 @@
# include <sys/dcmd_cam.h>
#endif

-#include "common.h"
-
-#include "ioctl.h"
-
/*****************************************************************************
* Local prototypes, BeOS specific
*****************************************************************************/
@@ -119,7 +116,7 @@ static int SolarisSendUSCSI( int fd, struct uscsi_cmd *p_sc );
/*****************************************************************************
* Local prototypes, win32 (aspi) specific
*****************************************************************************/
-#if defined( WIN32 )
+#if defined( WIN32_DVD_API )
static void WinInitSPTD ( SCSI_PASS_THROUGH_DIRECT *, int );
static void WinInitSSC ( struct SRB_ExecSCSICmd *, int );
static int WinSendSSC ( int, struct SRB_ExecSCSICmd * );
@@ -213,7 +210,7 @@ int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )

*pi_copyright = dvdbs.copyrightProtectionSystemType;

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
INIT_SPTD( GPCMD_READ_DVD_STRUCTURE, 8 );
@@ -373,7 +370,7 @@ int ioctl_ReadDiscKey( int i_fd, int *pi_agid, uint8_t *p_key )

memcpy( p_key, dvdbs.discKeyStructures, DVD_DISCKEY_SIZE );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -541,7 +538,7 @@ int ioctl_ReadTitleKey( int i_fd, int *pi_agid, int i_pos, uint8_t *p_key )

memcpy( p_key, dvdbs.titleKeyValue, DVD_KEY_SIZE );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -687,7 +684,7 @@ int ioctl_ReportAgid( int i_fd, int *pi_agid )

*pi_agid = dvdbs.grantID;

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
ULONG id;
@@ -808,7 +805,7 @@ int ioctl_ReportChallenge( int i_fd, int *pi_agid, uint8_t *p_challenge )

memcpy( p_challenge, dvdbs.challengeKeyValue, DVD_CHALLENGE_SIZE );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -940,7 +937,7 @@ int ioctl_ReportASF( int i_fd, int *pi_remove_me, int *pi_asf )

*pi_asf = dvdbs.successFlag;

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1075,7 +1072,7 @@ int ioctl_ReportKey1( int i_fd, int *pi_agid, uint8_t *p_key )

memcpy( p_key, dvdbs.key1Value, DVD_KEY_SIZE );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1192,7 +1189,7 @@ int ioctl_InvalidateAgid( int i_fd, int *pi_agid )

i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1320,7 +1317,7 @@ int ioctl_SendChallenge( int i_fd, int *pi_agid, uint8_t *p_challenge )

i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1457,7 +1454,7 @@ int ioctl_SendKey2( int i_fd, int *pi_agid, uint8_t *p_key )

i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1603,7 +1600,7 @@ int ioctl_ReportRPC( int i_fd, int *p_type, int *p_mask, int *p_scheme )
*p_mask = dvdbs.driveRegion;
*p_scheme = dvdbs.rpcScheme;

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
DWORD tmp;
@@ -1746,7 +1743,7 @@ int ioctl_SendRPC( int i_fd, int i_pdrc )

i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );

-#elif defined( WIN32 )
+#elif defined( WIN32_DVD_API )
if( WIN2K ) /* NT/2k/XP */
{
INIT_SPTD( GPCMD_SEND_KEY, 8 );
@@ -1969,7 +1966,7 @@ static int SolarisSendUSCSI( int i_fd, struct uscsi_cmd *p_sc )
}
#endif

-#if defined( WIN32 )
+#if defined( WIN32_DVD_API )
/*****************************************************************************
* WinInitSPTD: initialize a sptd structure
*****************************************************************************
diff --git a/src/ioctl.h b/src/ioctl.h
index c0bc7d5..bc423b8 100644
--- a/src/ioctl.h
+++ b/src/ioctl.h
@@ -24,6 +24,10 @@
#ifndef DVDCSS_IOCTL_H
#define DVDCSS_IOCTL_H

+#if defined( WIN32 ) || defined( SYS_CYGWIN )
+# define WIN32_DVD_API
+#endif
+
int ioctl_ReadCopyright ( int, int, int * );
int ioctl_ReadDiscKey ( int, int *, uint8_t * );
int ioctl_ReadTitleKey ( int, int *, int, uint8_t * );
@@ -101,7 +105,7 @@ int ioctl_SendRPC ( int, int );
/*****************************************************************************
* Common macro, win32 specific
*****************************************************************************/
-#if defined( WIN32 )
+#if defined( WIN32_DVD_API )
#define INIT_SPTD( TYPE, SIZE ) \
DWORD tmp; \
SCSI_PASS_THROUGH_DIRECT sptd; \
@@ -194,7 +198,7 @@ typedef union dvd_authinfo dvd_authinfo;
/*****************************************************************************
* win32 ioctl specific
*****************************************************************************/
-#if defined( WIN32 )
+#if defined( WIN32_DVD_API )

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
--
1.7.9.5
Jean-Baptiste Kempf
2013-02-01 15:08:07 UTC
Permalink
Post by Diego Biurrun
Now also fixing some leftover SYS_CYGWIN symbols ..
I still don't see the need to use WIN32_DVD_API.

CloseHandle and FreeLibrary and all those are WIN32 APIs, so they should
use this define.

Best regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Loading...