[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/20: build: syscalls: Add device-in-use?.
From: |
guix-commits |
Subject: |
01/20: build: syscalls: Add device-in-use?. |
Date: |
Wed, 5 Dec 2018 01:28:53 -0500 (EST) |
mothacehe pushed a commit to branch wip-newt-installer
in repository guix.
commit c91178e7f815bac80aecf269df984aec09eccad6
Author: Mathieu Othacehe <address@hidden>
Date: Wed Dec 5 14:08:35 2018 +0900
build: syscalls: Add device-in-use?.
This new procedure uses BLKRRPART to determine whether or not a device is
busy. It is useful when a device does not appear as mounted but is maybe
used
by the kernel. This is the case with overlayfs lowerdir backend device for
example.
* guix/build/syscalls.scm (device-in-use?): New exported procedure.
---
guix/build/syscalls.scm | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 56a689f..64d6239 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -73,6 +73,7 @@
file-system-mount-flags
statfs
free-disk-space
+ device-in-use?
processes
mkdtemp!
@@ -684,6 +685,27 @@ mounted at FILE."
(define AT_NO_AUTOMOUNT #x800)
(define AT_EMPTY_PATH #x1000)
+(define-syntax BLKRRPART ;<sys/mount.h>
+ (identifier-syntax #x125F))
+
+(define* (device-in-use? device)
+ "Return #t if the block DEVICE is in use, #f otherwise. This is inspired
+from fdisk_device_is_used function of util-linux. This is particulary useful
+for devices that do not appear in /proc/self/mounts like overlayfs lowerdir
+backend device."
+ (let*-values (((port) (open-file device "rb"))
+ ((ret err) (%ioctl (fileno port) BLKRRPART %null-pointer)))
+ (close-port port)
+ (cond
+ ((= ret 0)
+ #f)
+ ((= err EBUSY)
+ #t)
+ (else
+ (throw 'system-error "ioctl" "~A"
+ (list (strerror err))
+ (list err))))))
+
;;;
;;; Containers.
- branch wip-newt-installer updated (177029b -> 4781503), guix-commits, 2018/12/05
- 02/20: services: herd: Allow to pass arguments to start-service., guix-commits, 2018/12/05
- 05/20: build: file-systems: Export read-partition-label and read-partition-uuid., guix-commits, 2018/12/05
- 01/20: build: syscalls: Add device-in-use?.,
guix-commits <=
- 03/20: gnu: guile-newt: Update to revision 4., guix-commits, 2018/12/05
- 04/20: gnu: Add guile-parted., guix-commits, 2018/12/05
- 06/20: installer: Remove "selection" from all titles., guix-commits, 2018/12/05
- 13/20: installer: Redirect to TTY3 root shell for unguided install., guix-commits, 2018/12/05
- 07/20: installer: Add new utils., guix-commits, 2018/12/05
- 14/20: installer: Fix ethernet connection., guix-commits, 2018/12/05
- 11/20: installer: Add hostname., guix-commits, 2018/12/05
- 15/20: installer: Fix comments., guix-commits, 2018/12/05
- 09/20: installer: Do not ask for keyboard model., guix-commits, 2018/12/05
- 16/20: installer: Add user module., guix-commits, 2018/12/05