static string_t _root_device( const char * device,const char ** sys_device ) { size_t e ; ssize_t r ; string_t st = String( device ) ; if( StringStartsWithAtLeastOne( st,"/dev/sd","/dev/hd",NULL ) ){ /* * this path will convert something like: "/dev/sdc12" to "/dev/sdc". * basically,it removes digits from the end of the string to give the root device * required by tcplay's system volume or fde volume */ *sys_device = StringRemoveDigits( st ) ; }else if( StringStartsWith( st,"/dev/mmc" ) ){ /* * device path will be something like "/dev/mmcblk0p2" and what we want to do * is cut off the string from p to end iwth "/dev/mmcblk0" */ r = StringIndexOfChar( st,0,'p' ) ; if( r != -1 ){ e = StringLength( st ) - ( size_t )r ; *sys_device = StringRemoveRight( st,e ) ; }else{ *sys_device = StringContent( st ) ; } }else{ *sys_device = StringContent( st ) ; } return st ; }
static int _open_tcrypt_volume( const char * device,const open_struct_t * opts ) { tc_api_task task ; int r = !TC_OK ; size_t i ; size_t k ; const char * const * z ; const char * e ; string_t st = StringVoid ; if( tc_api_initialize() ){ task = tc_api_task_init( "map" ) ; if( tc_api_task_initialized( task ) ){ tc_api_task_set( task,"veracrypt_mode",opts->veraCrypt_volume ) ; tc_api_task_set( task,"map_name",opts->mapper_name ) ; if( StringHasComponent( opts->m_opts,"ro" ) ){ tc_api_task_set( task,"read_only" ) ; } if( opts->tcrypt_system ){ if( StringPrefixEqual( device,"/dev/sd" ) || StringPrefixEqual( device,"/dev/hd" ) ){ st = String( device ) ; e = StringRemoveDigits( st ) ; tc_api_task_set( task,"dev",e ) ; tc_api_task_set( task,"sys",e ) ; }else{ tc_api_task_set( task,"dev",device ) ; tc_api_task_set( task,"sys",device ) ; } }else{ tc_api_task_set( task,"dev",device ) ; } k = opts->tcrypt_keyfiles_count ; z = opts->tcrypt_keyfiles ; tc_api_task_set( task,"passphrase",opts->key ) ; for( i = 0 ; i < k ; i++ ){ tc_api_task_set( task,"keyfiles",*( z + i ) ) ; } r = tc_api_task_do( task ) ; tc_api_task_uninit( task ) ; StringDelete( &st ) ; } tc_api_uninit() ; } return r ; }
static int _zuluCryptCheckSYSifDeviceIsSystem( const char * device ) { /* * UDEV_SUPPORT is set at configure time by "-DUDEVSUPPORT=true" option,the option being absent equals "-DUDEVSUPPORT=false" * To set the option, configure with "-DUDEVSUPPORT=true" */ #if UDEV_SUPPORT /* * udev support is enabled */ int r ; size_t e ; ssize_t k ; string_t xt ; string_t st ; char dev[ PATH_MAX + 1 ] ; const char * path ; if( StringPrefixNotEqual( device,"/dev/" ) ){ /* * udev doesnt work with path to image files so return early */ return 0 ; } if( StringPrefixEqual( device,"/dev/loop" ) ){ /* * udev thinks all loop devices are system devices and we disagree and hence we return early */ return 0 ; } path = realpath( device,dev ) ; if( path != NULL ){ st = String( path ) ; }else{ st = String( device ) ; } if( StringStartsWithAtLeastOne( st,"/dev/sd","/dev/hd",NULL ) ){ /* * this path will convert something like: "/dev/sdc12" to "/dev/sdc" */ StringRemoveDigits( st ) ; }else if( StringStartsWith( st,"/dev/mmc" ) ){ /* * device path will be something like "/dev/mmcblk0p2" and what we want to do * is cut off the string from p to end iwth "/dev/mmcblk0" */ k = StringIndexOfChar( st,0,'p' ) ; if( k != -1 ){ e = StringLength( st ) - ( size_t )k ; StringRemoveRight( st,e ) ; } } StringReplaceString( st,"/dev/","/sys/block/" ) ; path = StringAppend( st,"/removable" ) ; /* * path will be something like "/sys/block/sda/removable" */ xt = StringGetFromVirtualFile( path ) ; StringDelete( &st ) ; if( xt == StringVoid ){ return 0 ; }else{ r = StringEqual( xt,"0\n" ) ; StringDelete( &xt ) ; return r ; } #else if( device ){;} /* * udev support is disabled */ return 0 ; #endif }