diff options
author | Mathieu Othacehe <m.othacehe@gmail.com> | 2018-12-05 14:08:35 +0900 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2019-01-17 14:04:22 +0100 |
commit | b08bea04978ee93696a2172c6c5fe2c08561a8a2 (patch) | |
tree | d737bfbbb7066f5b5cfd9ce59543b5ed1bcf3dc1 | |
parent | 4f83afd28a94ae4452423f36a4dcf2d1c2721e4f (diff) | |
download | guix-b08bea04978ee93696a2172c6c5fe2c08561a8a2.tar guix-b08bea04978ee93696a2172c6c5fe2c08561a8a2.tar.gz |
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.
-rw-r--r-- | guix/build/syscalls.scm | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index d75c11ada7..6f2a061f35 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. |