mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-27 04:59:27 -05:00
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.
This commit is contained in:
parent
4f83afd28a
commit
b08bea0497
1 changed files with 22 additions and 0 deletions
|
@ -73,6 +73,7 @@ (define-module (guix build syscalls)
|
||||||
file-system-mount-flags
|
file-system-mount-flags
|
||||||
statfs
|
statfs
|
||||||
free-disk-space
|
free-disk-space
|
||||||
|
device-in-use?
|
||||||
|
|
||||||
processes
|
processes
|
||||||
mkdtemp!
|
mkdtemp!
|
||||||
|
@ -684,6 +685,27 @@ (define AT_SYMLINK_FOLLOW #x400)
|
||||||
(define AT_NO_AUTOMOUNT #x800)
|
(define AT_NO_AUTOMOUNT #x800)
|
||||||
(define AT_EMPTY_PATH #x1000)
|
(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.
|
;;; Containers.
|
||||||
|
|
Loading…
Reference in a new issue