From 715fc9d44d284a0c5e1ded45091eaf979aa5ecd4 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 18 Sep 2014 20:19:56 +0200 Subject: syscalls: Add 'swapon' and 'swapoff'. * guix/build/syscalls.scm (swapon, swapoff): New procedures. * tests/syscalls.scm ("swapon, ENOENT/EPERM", "swapoff, EINVAL/EPERM"): New tests. --- guix/build/syscalls.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'guix/build/syscalls.scm') diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index c8ec13983b..f910ebd152 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -31,6 +31,8 @@ (define-module (guix build syscalls) MS_MOVE mount umount + swapon + swapoff processes IFF_UP @@ -164,6 +166,30 @@ (define umount (when update-mtab? (remove-from-mtab target)))))) +(define swapon + (let* ((ptr (dynamic-func "swapon" (dynamic-link))) + (proc (pointer->procedure int ptr (list '* int)))) + (lambda* (device #:optional (flags 0)) + "Use the block special device at DEVICE for swapping." + (let ((ret (proc (string->pointer device) flags)) + (err (errno))) + (unless (zero? ret) + (throw 'system-error "swapon" "~S: ~A" + (list device (strerror err)) + (list err))))))) + +(define swapoff + (let* ((ptr (dynamic-func "swapoff" (dynamic-link))) + (proc (pointer->procedure int ptr '(*)))) + (lambda (device) + "Stop using block special device DEVICE for swapping." + (let ((ret (proc (string->pointer device))) + (err (errno))) + (unless (zero? ret) + (throw 'system-error "swapff" "~S: ~A" + (list device (strerror err)) + (list err))))))) + (define (kernel? pid) "Return #t if PID designates a \"kernel thread\" rather than a normal user-land process." -- cgit v1.2.3