From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nm3-vm6.bullet.mail.ne1.yahoo.com (nm3-vm6.bullet.mail.ne1.yahoo.com [98.138.91.96]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mail.server123.net (Postfix) with ESMTPS for ; Sat, 26 Sep 2015 03:04:55 +0200 (CEST) Date: Sat, 26 Sep 2015 01:03:44 +0000 (UTC) From: H McCurdy Reply-To: H McCurdy Message-ID: <1087656308.1214643.1443229424819.JavaMail.yahoo@mail.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1214642_329404628.1443229424817" Subject: [dm-crypt] Question about "An example of using LUKS device through libcryptsetup API" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "dm-crypt@saout.de" ------=_Part_1214642_329404628.1443229424817 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, The program code is published athttps://gitlab.com/cryptsetup/cryptsetup/wi= kis/API/index.html Looking in=20 static int handle_active_device(const char *device_name) at =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (crypt_status(cd, device= _name) =3D=3D CRYPT_ACTIVE) printf("Device %s is still active.\n", device_name); else { printf("Something failed perhaps, device %s is not active.\= n", device_name); crypt_free(cd); return -1; } /* * crypt_deactivate() is used to deactivate device */ r =3D crypt_deactivate(cd, device_name); if (r < 0) { printf("crypt_deactivate() failed.\n"); crypt_free(cd); return r; } But if I look in /usr/include/libcryptsetup.h, I see typedef enum { CRYPT_INVALID, /**< device mapping is invalid in this context */ CRYPT_INACTIVE, /**< no such mapped device */ CRYPT_ACTIVE, /**< device is active */ CRYPT_BUSY /**< device is active and has open count > 0 */ } crypt_status_info; and crypt_status_info crypt_status(struct crypt_device *cd, const char *name); It appears to me that the code flow is good since we probably can't deactiv= ate a busy container but it appears to me that the error is misleading in the event of CRYPT_BUS= Y because the message indicates the device isn't active. Am I interpreting correctly? Hugh ------=_Part_1214642_329404628.1443229424817 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

The pr= ogram code is published at

Looking in 

static
int handle_active_device(const char *device_name)

at
    &nbs= p;   if (crypt_status(cd, device_name) =3D=3D CRYPT_ACTIVE)<= br> printf("Device %s is still active.\n", device_name);
else {
printf("Someth= ing failed perhaps, device %s is not active.\n", device_name);
crypt_free(cd); return -= 1;
}

/*
* crypt_deactivate() is used to deactivate device
*/
r =3D crypt_deactivate(cd, = device_name);
= if (r < 0) {
= printf("crypt_deactivate() failed.\n");
crypt_free(cd);
return r;
}

But if I look in= /usr/include/libcryptsetup.h, I see

typedef enum {
CRYPT_INVALID, /**< device mappin= g is invalid in this context */
CRYPT_INACTIVE, /**< no such mapped device */
CRYPT_ACTIVE, /**< device is ac= tive */
CRYPT_BUSY /= **< device is active and has open count > 0 */
} crypt_status_info;

and

crypt_status_info crypt_status(struct crypt_device *cd,= const char *name);

It appears to me that the code flow is good sinc= e we probably can't deactivate a busy container
but it appears to me tha= t the error is misleading in the event of CRYPT_BUSY because the messageindicates the device isn't active.

Am I interpreting correctly?
=
Hugh


------=_Part_1214642_329404628.1443229424817-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-x229.google.com (mail-wi0-x229.google.com [IPv6:2a00:1450:400c:c05::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.server123.net (Postfix) with ESMTPS for ; Sat, 26 Sep 2015 08:11:55 +0200 (CEST) Received: by wicfx3 with SMTP id fx3so42671404wic.0 for ; Fri, 25 Sep 2015 23:11:53 -0700 (PDT) References: <1087656308.1214643.1443229424819.JavaMail.yahoo@mail.yahoo.com> From: Milan Broz Message-ID: <56063727.2030809@gmail.com> Date: Sat, 26 Sep 2015 08:11:51 +0200 MIME-Version: 1.0 In-Reply-To: <1087656308.1214643.1443229424819.JavaMail.yahoo@mail.yahoo.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [dm-crypt] Question about "An example of using LUKS device through libcryptsetup API" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: H McCurdy , "dm-crypt@saout.de" On 09/26/2015 03:03 AM, H McCurdy wrote: > Hi, > > The program code is published at > https://gitlab.com/cryptsetup/cryptsetup/wikis/API/index.html > > Looking in > > static int handle_active_device(const char *device_name) > > at > if (crypt_status(cd, device_name) == CRYPT_ACTIVE) > printf("Device %s is still active.\n", device_name); > else { > printf("Something failed perhaps, device %s is not active.\n", device_name); > crypt_free(cd); > return -1; > } > > /* > * crypt_deactivate() is used to deactivate device > */ > r = crypt_deactivate(cd, device_name); > if (r < 0) { > printf("crypt_deactivate() failed.\n"); > crypt_free(cd); > return r; > } > > But if I look in /usr/include/libcryptsetup.h, I see > > typedef enum { > CRYPT_INVALID, /**< device mapping is invalid in this context */ > CRYPT_INACTIVE, /**< no such mapped device */ > CRYPT_ACTIVE, /**< device is active */ > CRYPT_BUSY /**< device is active and has open count > 0 */ > } crypt_status_info; > > and > > crypt_status_info crypt_status(struct crypt_device *cd, const char *name); > > It appears to me that the code flow is good since we probably can't deactivate a busy container > but it appears to me that the error is misleading in the event of CRYPT_BUSY because the message > indicates the device isn't active. > > Am I interpreting correctly? Yes, that example should probably handle busy device differently. Anyway, you will receive error message "Device ... is still in use." before the printf above. Milan From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nm3-vm5.bullet.mail.ne1.yahoo.com (nm3-vm5.bullet.mail.ne1.yahoo.com [98.138.91.225]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mail.server123.net (Postfix) with ESMTPS for ; Sat, 26 Sep 2015 21:13:19 +0200 (CEST) Date: Sat, 26 Sep 2015 19:13:16 +0000 (UTC) From: H McCurdy Reply-To: H McCurdy Message-ID: <1557008712.1411173.1443294796335.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <56063727.2030809@gmail.com> References: <56063727.2030809@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1411172_151808649.1443294796330" Subject: Re: [dm-crypt] Question about "An example of using LUKS device through libcryptsetup API" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Milan Broz , "dm-crypt@saout.de" ------=_Part_1411172_151808649.1443294796330 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks Milan, What I'm trying to do is write my own program that is fairly automatic and = smart.=C2=A0 If the device is busy, it may want to try again. The information you provided helps me.=C2=A0 Thank you. Hugh=20 On Saturday, September 26, 2015 2:12 AM, Milan Broz wrote: =20 On 09/26/2015 03:03 AM, H McCurdy wrote: > Hi, >=20 > The program code is published at > https://gitlab.com/cryptsetup/cryptsetup/wikis/API/index.html >=20 > Looking in=20 >=20 > static int handle_active_device(const char *device_name) >=20 > at >=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (crypt_status(cd, device_name) =3D=3D CRYPT= _ACTIVE) >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("Device %s = is still active.\n", device_name); >=C2=A0 =C2=A0 =C2=A0 =C2=A0 else { >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("Something = failed perhaps, device %s is not active.\n", device_name); >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 crypt_free(cd); >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -1; >=C2=A0 =C2=A0 =C2=A0 =C2=A0 } >=20 >=C2=A0 =C2=A0 =C2=A0 =C2=A0 /* >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * crypt_deactivate() is used to deactiv= ate device >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 */ >=C2=A0 =C2=A0 =C2=A0 =C2=A0 r =3D crypt_deactivate(cd, device_name); >=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (r < 0) { >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf("crypt_deac= tivate() failed.\n"); >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 crypt_free(cd); >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r; >=C2=A0 =C2=A0 =C2=A0 =C2=A0 } >=20 > But if I look in /usr/include/libcryptsetup.h, I see >=20 > typedef enum { >=C2=A0 CRYPT_INVALID, /**< device mapping is invalid in this context */ >=C2=A0 CRYPT_INACTIVE, /**< no such mapped device */ >=C2=A0 CRYPT_ACTIVE, /**< device is active */ >=C2=A0 CRYPT_BUSY /**< device is active and has open count > 0 */ > } crypt_status_info; >=20 > and >=20 > crypt_status_info crypt_status(struct crypt_device *cd, const char *name)= ; >=20 > It appears to me that the code flow is good since we probably can't deact= ivate a busy container > but it appears to me that the error is misleading in the event of CRYPT_B= USY because the message > indicates the device isn't active. >=20 > Am I interpreting correctly? Yes, that example should probably handle busy device differently. Anyway, you will receive error message "Device ... is still in use." before= the printf above. Milan _______________________________________________ dm-crypt mailing list dm-crypt@saout.de http://www.saout.de/mailman/listinfo/dm-crypt ------=_Part_1411172_151808649.1443294796330 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks Milan,

What I'm trying to do is write my own program that is fairly au= tomatic and smart.  If the device is busy, it may want to try again.

The information you provided helps me.  Thank you.

Hugh



On Saturday, September 26, 2015 2:12 AM, Milan Broz <gmazyland= @gmail.com> wrote:


On 09/26/2015 03:03 AM, H McCurdy wrote:

> Hi,
>
> The program code is published at
> = https://gitlab.com/cryptsetup/cryptsetup/wi= kis/API/index.html
>
> Looki= ng in
>
> static int handle_act= ive_device(const char *device_name)
>
> at
>        if (crypt_sta= tus(cd, device_name) =3D=3D CRYPT_ACTIVE)
>  &nbs= p;             printf("Device %s is still ac= tive.\n", device_name);
>        = else {
>            &nbs= p;   printf("Something failed perhaps, device %s is not active.\n", d= evice_name);
>           = ;     crypt_free(cd);
>     =           return -1;
> = ;       }
>
>&nb= sp;       /*
>      &nb= sp;   * crypt_deactivate() is used to deactivate device
>          */
>  =       r =3D crypt_deactivate(cd, device_name);
>        if (r < 0) {
&g= t;                printf("crypt_de= activate() failed.\n");
>        &= nbsp;       crypt_free(cd);
>  &n= bsp;             return r;
>        }
>
> But if I look in /usr/include/libcryptsetup.h, I see
>
> typedef enum {
> = ; CRYPT_INVALID, /**< device mapping is invalid in this context */
>  CRYPT_INACTIVE, /**< no such mapped device */<= br clear=3D"none">>  CRYPT_ACTIVE, /**< device is active */
>  CRYPT_BUSY /**< device is active and has open= count > 0 */
> } crypt_status_info;
>
> and
>
> crypt_status_info crypt_status(struct crypt_device *cd, const char= *name);
>
> It appears to me th= at the code flow is good since we probably can't deactivate a busy containe= r
> but it appears to me that the error is misleading = in the event of CRYPT_BUSY because the message
> indic= ates the device isn't active.
>
>= ; Am I interpreting correctly?


Y= es, that example should probably handle busy device differently.

Anyway, you will receive error message "Device= ... is still in use." before the printf above.

Milan
_________________________________________= ______
dm-crypt mailing list
dm-crypt@saout.de
http://www.sa= out.de/mailman/listinfo/dm-crypt



------=_Part_1411172_151808649.1443294796330--