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 _not_removed( stringList_t stl,StringListIterator it,StringListIterator * end ) { string_t st = *it ; StringListIterator e = it + 1 ; if( StringStartsWithAtLeastOne( st,"/dev/sd","/dev/hd","/dev/mmcblk",NULL ) ){ /* * we have a partition,lets continue */ if( e != *end ){ /* * we are not at the end of the list,ie,there is atleast one more entry */ if( StringStartsWith_1( *e,st ) ){ /* * *e will contain something like "/dev/sdc3" * st will contain something like "/dev/sdc" * * This device is partitioned and hence we remove the "/dev/sdc" entry * from the list since we dont care about it. */ StringListRemoveAt_1( stl,it,end ) ; return 0 ; } } } return 1 ; }
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 }