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