[dm-crypt] help with understanding cryptsetup through the library

.. ink .. mhogomchungu at gmail.com
Sun Oct 2 23:18:25 CEST 2011

trying to switch from using cryptsetup in the commandline to using the
library and i am having a bit of a problem understanding the library

what am doing wrong in the following code? i can not seem to get a handle
and use it correctly.


int main( int argc, char *argv[] )
struct crypt_device *cd ;
 char * device = argv[1] ;
int i ;
 const char *c ;
 printf("device in use: %s\n",device);
 i = crypt_init( &cd ,device);
 if ( i != 0 ){
perror("") ;
return 1 ;

c = crypt_get_type( cd ) ;
 if ( c == NULL )
printf("device not known\n") ;
printf("%s\n",c );

crypt_free( cd ) ;
return 0 ;

running the above code gives this output:
device in use: /home/ink/cs/luks
device not known

It does not seem to know the device. But the device is a luks device and the
following command proves it

cryptsetup isLuks /home/ink/cs/luks ; echo $?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.saout.de/pipermail/dm-crypt/attachments/20111002/345ab1ea/attachment.html>

More information about the dm-crypt mailing list