[libdvdcss-devel] [Git][videolan/libdvdcss][master] 4 commits: Rename BeInitRDC to HaikuInitRDC

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Jul 4 13:04:26 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdcss


Commits:
91de0848 by Jérôme Duval at 2026-07-04T12:38:57+02:00
Rename BeInitRDC to HaikuInitRDC

fix space alignment

- - - - -
ea7166f1 by Jérôme Duval at 2026-07-04T12:38:57+02:00
Handle device errors on Haiku like on other platforms

- - - - -
7c6bdc0c by Jérôme Duval at 2026-07-04T12:38:57+02:00
Implement ioctl_ReadCPRMMediaId() and ioctl_ReadCPRMMKBPack() for Haiku

- - - - -
f73dc860 by Jérôme Duval at 2026-07-04T12:38:57+02:00
Use Haiku directory API to get the cache folder for Haiku

- - - - -


3 changed files:

- src/ioctl.c
- src/ioctl.h
- src/libdvdcss.c


Changes:

=====================================
src/ioctl.c
=====================================
@@ -103,7 +103,7 @@
  * Local prototypes, OS-specific
  *****************************************************************************/
 #if defined( __HAIKU__ )
-static void BeInitRDC ( raw_device_command *, int );
+static void HaikuInitRDC ( raw_device_command *, int );
 #elif defined( SOLARIS_USCSI )
 static void SolarisInitUSCSI( struct uscsi_cmd *p_sc, int i_type );
 static int SolarisSendUSCSI( int fd, struct uscsi_cmd *p_sc );
@@ -149,6 +149,8 @@ int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )
     rdc.command[ 7 ] = DVD_STRUCT_COPYRIGHT;
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
     *pi_copyright = p_buffer[ 4 ];
 
@@ -279,11 +281,8 @@ int ioctl_ReadDiscKey( int i_fd, const int *pi_agid, uint8_t *p_key )
     rdc.command[ 10 ] = *pi_agid << 6;
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
-
-    if( i_ret < 0 )
-    {
-        return i_ret;
-    }
+    if( i_ret < 0 || rdc.scsi_status != 0 )
+		return -1;
 
     memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
 
@@ -407,6 +406,8 @@ int ioctl_ReadTitleKey( int i_fd, const int *pi_agid, int i_pos, uint8_t *p_key
     rdc.command[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
     memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
 
@@ -533,6 +534,8 @@ int ioctl_ReportAgid( int i_fd, int *pi_agid )
     rdc.command[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
     *pi_agid = p_buffer[ 7 ] >> 6;
 
@@ -628,6 +631,8 @@ int ioctl_ReportChallenge( int i_fd, const int *pi_agid, uint8_t *p_challenge )
     rdc.command[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
     memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
 
@@ -736,6 +741,8 @@ int ioctl_ReportASF( int i_fd, int *pi_asf )
     rdc.command[ 10 ] = DVD_REPORT_ASF;
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
     *pi_asf = p_buffer[ 7 ] & 1;
 
@@ -846,6 +853,8 @@ int ioctl_ReportKey1( int i_fd, const int *pi_agid, uint8_t *p_key )
     rdc.command[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
     memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
 
@@ -945,6 +954,8 @@ int ioctl_InvalidateAgid( int i_fd, int *pi_agid )
     rdc.command[ 10 ] = DVDCSS_INVALIDATE_AGID | (*pi_agid << 6);
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_REPORT_KEY, 0 );
@@ -1066,6 +1077,27 @@ int ioctl_ReadCPRMMediaId(int i_fd,int *p_agid, uint8_t *p_data_buffer)
             p_data_buffer + 4,
             CPRM_MEDIA_ID_SIZE);
 
+#elif defined( __HAIKU__ )
+	raw_device_command rdc = { 0 };
+    uint8_t dvdbs[CPRM_MEDIA_ID_SIZE + 4];
+    rdc.data = dvdbs;
+    rdc.data_length = sizeof(dvdbs); \
+    HaikuInitRDC( &rdc, GPCMD_READ_DVD_STRUCTURE );
+
+    rdc.command[ 7 ]  = CPRM_STRUCT_MEDIA_ID;
+    rdc.command[ 10 ] = *p_agid << 6;
+
+    i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+
+    if( i_ret < 0 )
+    {
+        return i_ret;
+    }
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
+    if( i_ret == 0 )
+        memcpy( p_buffer, dvdbs + 4, CPRM_MEDIA_ID_SIZE);
+
 #elif defined( DARWIN_DVD_IOCTL )
     dk_dvd_read_structure_t dvd = { 0 };
     uint8_t dvdbs[CPRM_MEDIA_ID_SIZE + 4] = { 0 };
@@ -1149,6 +1181,32 @@ int ioctl_ReadCPRMMKBPack(int i_fd, int *p_agid, int mkb_pack, uint8_t *p_mkb_pa
     memcpy( p_mkb_pack, sptd_buf + 4, CPRM_MKB_PACK_SIZE );
     free( sptd_buf );
 
+#elif defined( __HAIKU__ )
+	raw_device_command rdc = { 0 };
+	uint8_t *sptd_buf = malloc( CPRM_MKB_PACK_SIZE + 4 );
+    rdc.data = sptd_buf;
+    rdc.data_length = CPRM_MKB_PACK_SIZE + 4; \
+    HaikuInitRDC( &rdc, GPCMD_READ_DVD_STRUCTURE );
+
+    rdc.command[ 2 ] = (uint8_t)( ( mkb_pack >> 24 ) & 0xFF );
+    rdc.command[ 3 ] = (uint8_t)( ( mkb_pack >> 16 ) & 0xFF );
+    rdc.command[ 4 ] = (uint8_t)( ( mkb_pack >> 8 )  & 0xFF );
+    rdc.command[ 5 ] = (uint8_t)( mkb_pack & 0xFF );
+    rdc.command[ 7 ]  = CPRM_STRUCT_MKB;
+    rdc.command[ 10 ] = *p_agid << 6;
+
+    i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+
+    if( i_ret < 0 || rdc.scsi_status != 0 )
+    {
+        free(sptd_buf);
+        return i_ret;
+    }
+
+    *p_total_packs = sptd_buf[3];
+    memcpy( p_mkb_pack, sptd_buf + 4, CPRM_MKB_PACK_SIZE);
+    free(sptd_buf);
+
 #elif defined( DARWIN_DVD_IOCTL )
     dk_dvd_read_structure_t dvd = { 0 };
     uint8_t dvdbs[CPRM_MKB_PACK_SIZE + 4] = { 0 };
@@ -1257,6 +1315,8 @@ int ioctl_SendChallenge( int i_fd, const int *pi_agid, const uint8_t *p_challeng
     memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_SEND_KEY, 16 );
@@ -1366,6 +1426,8 @@ int ioctl_SendKey2( int i_fd, const int *pi_agid, const uint8_t *p_key )
     memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
 #elif defined( SOLARIS_USCSI )
     INIT_USCSI( GPCMD_SEND_KEY, 12 );
@@ -1478,6 +1540,8 @@ int ioctl_ReportRPC( int i_fd, int *p_type, int *p_mask, int *p_scheme )
     rdc.command[ 10 ] = DVD_REPORT_RPC;
 
     i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
+    if( i_ret == 0 && rdc.scsi_status != 0 )
+        i_ret = -1;
 
     *p_type = p_buffer[ 4 ] >> 6;
     *p_mask = p_buffer[ 5 ];
@@ -1570,12 +1634,12 @@ int ioctl_ReportRPC( int i_fd, int *p_type, int *p_mask, int *p_scheme )
 
 #if defined( __HAIKU__ )
 /*****************************************************************************
- * BeInitRDC: initialize a RDC structure for the Haiku kernel
+ * HaikuInitRDC: initialize a RDC structure for the Haiku kernel
  *****************************************************************************
  * This function initializes a Haiku raw device command structure for future
  * use, either a read command or a write command.
  *****************************************************************************/
-static void BeInitRDC( raw_device_command *p_rdc, int i_type )
+static void HaikuInitRDC( raw_device_command *p_rdc, int i_type )
 {
     memset( p_rdc->data, 0, p_rdc->data_length );
 
@@ -1586,7 +1650,9 @@ static void BeInitRDC( raw_device_command *p_rdc, int i_type )
             break;
 
         case GPCMD_READ_DVD_STRUCTURE: case GPCMD_REPORT_KEY:
-    p_rdc->flags = B_RAW_DEVICE_DATA_IN; break; }
+            p_rdc->flags = B_RAW_DEVICE_DATA_IN;
+            break;
+    }
 
     p_rdc->command[ 0 ]      = i_type;
 


=====================================
src/ioctl.h
=====================================
@@ -52,7 +52,7 @@ int ioctl_ReadCPRMMediaId   ( int, int *, uint8_t * );
     uint8_t p_buffer[ (SIZE)+1 ]; \
     rdc.data = (char *)p_buffer; \
     rdc.data_length = (SIZE); \
-    BeInitRDC( &rdc, (TYPE) );
+    HaikuInitRDC( &rdc, (TYPE) );
 #elif defined( SOLARIS_USCSI )
 #define INIT_USCSI( TYPE, SIZE ) \
     struct uscsi_cmd sc = { 0 }; \


=====================================
src/libdvdcss.c
=====================================
@@ -121,6 +121,9 @@
 #   include <windows.h>
 #   include <shlobj.h>
 #endif
+#ifdef __HAIKU__
+#   include <FindDirectory.h>
+#endif
 
 #include "dvdcss/dvdcss.h"
 
@@ -281,8 +284,17 @@ static int set_cache_directory( dvdcss_t dvdcss )
                 }
             }
 #endif /* __OS2__ */
+#ifdef __HAIKU__
+            {
+                char buf[512];
+                find_directory(B_USER_CACHE_DIRECTORY, 0, false, buf, 512);
+                snprintf( dvdcss->psz_cachefile + home_pos, PATH_MAX - home_pos,
+                          "%s/dvdcss", buf );
+		    }
+#else
             snprintf( dvdcss->psz_cachefile + home_pos, PATH_MAX - home_pos,
                       "%s/.dvdcss", psz_home );
+#endif
             dvdcss->psz_cachefile[PATH_MAX - 1] = '\0';
             psz_cache = dvdcss->psz_cachefile;
         }



View it on GitLab: https://code.videolan.org/videolan/libdvdcss/-/compare/891f8fb5c45baf70bfbd67d973d1d4f0b10fd0aa...f73dc860cb71f81f3126a08a6deffcaea3f64e55

-- 
View it on GitLab: https://code.videolan.org/videolan/libdvdcss/-/compare/891f8fb5c45baf70bfbd67d973d1d4f0b10fd0aa...f73dc860cb71f81f3126a08a6deffcaea3f64e55
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the libdvdcss-devel mailing list