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--