~ruther/guix-local

ccea821befc96a2c5e0c64b1a18eef0f31abe0a7 — Ludovic Courtès 11 years ago 7eda0c5
syscalls: Add 'mount-points'.

* guix/build/syscalls.scm (mount-points): New procedure.
* tests/syscalls.scm ("mount-points"): New test.
2 files changed, 16 insertions(+), 0 deletions(-)

M guix/build/syscalls.scm
M tests/syscalls.scm
M guix/build/syscalls.scm => guix/build/syscalls.scm +13 -0
@@ 31,6 31,7 @@
            MS_MOVE
            mount
            umount
            mount-points
            swapon
            swapoff
            processes


@@ 166,6 167,18 @@ constants from <sys/mount.h>."
        (when update-mtab?
          (remove-from-mtab target))))))

(define (mount-points)
  "Return the mounts points for currently mounted file systems."
  (call-with-input-file "/proc/mounts"
    (lambda (port)
      (let loop ((result '()))
        (let ((line (read-line port)))
          (if (eof-object? line)
              (reverse result)
              (match (string-tokenize line)
                ((source mount-point _ ...)
                 (loop (cons mount-point result))))))))))

(define swapon
  (let* ((ptr  (dynamic-func "swapon" (dynamic-link)))
         (proc (pointer->procedure int ptr (list '* int))))

M tests/syscalls.scm => tests/syscalls.scm +3 -0
@@ 44,6 44,9 @@
      ;; Both return values have been encountered in the wild.
      (memv (system-error-errno args) (list EPERM ENOENT)))))

(test-assert "mount-points"
  (member "/" (mount-points)))

(test-assert "swapon, ENOENT/EPERM"
  (catch 'system-error
    (lambda ()