comparison libmpdvdkit2/ioctl.c @ 16630:954cdf2171f6

upgrade to libdvdcss 1.2.9
author diego
date Sat, 01 Oct 2005 17:19:33 +0000
parents c2ddedd0619e
children
comparison
equal deleted inserted replaced
16629:045e93202e4a 16630:954cdf2171f6
1 /***************************************************************************** 1 /*****************************************************************************
2 * ioctl.c: DVD ioctl replacement function 2 * ioctl.c: DVD ioctl replacement function
3 ***************************************************************************** 3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN 4 * Copyright (C) 1999-2001 VideoLAN
5 *
6 * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff.
7 * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
8 * $Id$ 5 * $Id$
9 * 6 *
10 * Authors: Markus Kuespert <ltlBeBoy@beosmail.com> 7 * Authors: Markus Kuespert <ltlBeBoy@beosmail.com>
11 * Samuel Hocevar <sam@zoy.org> 8 * Samuel Hocevar <sam@zoy.org>
12 * Jon Lech Johansen <jon-vl@nanocrew.net> 9 * Jon Lech Johansen <jon-vl@nanocrew.net>
1910 /***************************************************************************** 1907 /*****************************************************************************
1911 * SolarisSendUSCSI: send a USCSICMD structure to the Solaris kernel 1908 * SolarisSendUSCSI: send a USCSICMD structure to the Solaris kernel
1912 * for execution 1909 * for execution
1913 ***************************************************************************** 1910 *****************************************************************************
1914 * When available, this function uses the function smedia_uscsi_cmd() 1911 * When available, this function uses the function smedia_uscsi_cmd()
1915 * from solaris' libsmedia library (solaris 9 or newer) to execute the 1912 * from Solaris' libsmedia library (Solaris 9 or newer) to execute the
1916 * USCSI command. smedia_uscsi_cmd() allows USCSI commands for 1913 * USCSI command. smedia_uscsi_cmd() allows USCSI commands for
1917 * non-root users on removable media devices on solaris 9; sending the 1914 * non-root users on removable media devices on Solaris 9; sending the
1918 * USCSI command directly to the device using the USCSICMD ioctl fails 1915 * USCSI command directly to the device using the USCSICMD ioctl fails
1919 * with an EPERM error on solaris 9. 1916 * with an EPERM error on Solaris 9.
1920 * 1917 *
1921 * The code will fall back to the USCSICMD ioctl method, when 1918 * The code will fall back to the USCSICMD ioctl method, when
1922 * libsmedia.so is not available or does not export the 1919 * libsmedia.so is not available or does not export the
1923 * smedia_uscsi_cmd() function (on solaris releases upto and including 1920 * smedia_uscsi_cmd() function (on Solaris releases upto and including
1924 * solaris 8). Fortunatelly, on these old releases non-root users are 1921 * Solaris 8). Fortunatelly, on these old releases non-root users are
1925 * allowed to perform USCSICMD ioctls on removable media devices. 1922 * allowed to perform USCSICMD ioctls on removable media devices.
1926 *****************************************************************************/ 1923 *****************************************************************************/
1927 static int SolarisSendUSCSI( int i_fd, struct uscsi_cmd *p_sc ) { 1924 static int SolarisSendUSCSI( int i_fd, struct uscsi_cmd *p_sc )
1928 void *sm_hdl; 1925 {
1929 static int initialized; 1926 void *p_handle;
1930 static void* (*sm_get_handle)(int32_t); 1927
1931 static int (*sm_release_handle)(void*); 1928 /* We use static variables to keep track of the libsmedia symbols, which
1932 static int (*sm_uscsi_cmd)(void*, struct uscsi_cmd *); 1929 * is harmless even in a multithreaded program because the library and
1933 1930 * its symbols will always be mapped at the same address. */
1934 if (!initialized) 1931 static int b_tried = 0;
1935 { 1932 static int b_have_sm = 0;
1936 void *smedia_lib; 1933 static void * (*p_get_handle) ( int32_t );
1937 1934 static int (*p_uscsi_cmd) ( void *, struct uscsi_cmd * );
1938 smedia_lib = dlopen("libsmedia.so", RTLD_NOW); 1935 static int (*p_release_handle) ( void * );
1939 if (smedia_lib) { 1936
1940 sm_get_handle = dlsym(smedia_lib, "smedia_get_handle"); 1937 if( !b_tried )
1941 sm_release_handle = dlsym(smedia_lib, "smedia_release_handle"); 1938 {
1942 sm_uscsi_cmd = dlsym(smedia_lib, "smedia_uscsi_cmd"); 1939 void *p_lib;
1943 } 1940
1944 initialized = 1; 1941 p_lib = dlopen( "libsmedia.so", RTLD_NOW );
1945 } 1942 if( p_lib )
1946 1943 {
1947 if (sm_get_handle && sm_uscsi_cmd && sm_release_handle 1944 p_get_handle = dlsym( p_lib, "smedia_get_handle" );
1948 && (sm_hdl = sm_get_handle(i_fd))) 1945 p_uscsi_cmd = dlsym( p_lib, "smedia_uscsi_cmd" );
1949 { 1946 p_release_handle = dlsym( p_lib, "smedia_release_handle" );
1950 int i_ret = sm_uscsi_cmd(sm_hdl, p_sc); 1947
1951 sm_release_handle(sm_hdl); 1948 if( p_get_handle && p_uscsi_cmd && p_release_handle )
1952 return i_ret; 1949 {
1950 b_have_sm = 1;
1951 }
1952 else
1953 {
1954 dlclose( p_lib );
1955 }
1956 }
1957
1958 b_tried = 1;
1959 }
1960
1961 if( b_have_sm && (p_handle = p_get_handle(i_fd)) )
1962 {
1963 int i_ret = p_uscsi_cmd( p_handle, p_sc );
1964 p_release_handle( p_handle );
1965 return i_ret;
1953 } 1966 }
1954 1967
1955 return ioctl( i_fd, USCSICMD, p_sc ); 1968 return ioctl( i_fd, USCSICMD, p_sc );
1956 } 1969 }
1957 #endif 1970 #endif